dispatch.hosting.inc

Drush include for the Hosting module's dispatch command.

Functions

Namesort descending Description
drush_hosting_dispatch Main queue processing drush command for hostmaster.

File

dispatch.hosting.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Drush include for the Hosting module's dispatch command.
  5. */
  6. /**
  7. * Main queue processing drush command for hostmaster.
  8. *
  9. * This is a single command, which will (based on configuration) run all the
  10. * other queue commands (cron, backup, tasks, stats). This is done so that there
  11. * is only one cron job to configure, and allow the frequency of calls to be
  12. * configured from the frontend interface.
  13. */
  14. function drush_hosting_dispatch() {
  15. $now = REQUEST_TIME;
  16. variable_set("hosting_dispatch_last_run", $now);
  17. drush_log(dt("Dispatching queues."));
  18. $platform = node_load(HOSTING_OWN_PLATFORM);
  19. $root = $platform->publish_path;
  20. if (variable_get('hosting_dispatch_enabled', FALSE)) {
  21. $queues = hosting_get_queues();
  22. foreach ($queues as $queue => $info) {
  23. $semaphore = "hosting_dispatch_{$queue}_running";
  24. $lock_wait = drush_get_option('lock-wait', HOSTING_QUEUE_DEFAULT_LOCK_WAIT);
  25. if (!lock_wait($semaphore, $lock_wait) || drush_get_option('force', FALSE)) {
  26. if (lock_acquire($semaphore, HOSTING_QUEUE_LOCK_TIMEOUT)) {
  27. drush_log(dt('Acquired lock on @queue queue.', array('@queue' => $queue)));
  28. }
  29. elseif (drush_get_option('force', FALSE)) {
  30. drush_log(dt('Bypassing lock on @queue queue.', array('@queue' => $queue)), 'warning');
  31. }
  32. else {
  33. drush_die(dt('Cannot acquire lock on @queue queue.', array('@queue' => $queue)));
  34. }
  35. }
  36. else {
  37. drush_die(dt("Cannot acquire lock on @queue queue after waiting @wait seconds. A longer wait time can be set with the --lock-wait option.", array('@queue' => $queue, '@wait' => $lock_wait)));
  38. }
  39. if ($info['enabled']) {
  40. if (($now - $info["last"]) >= $info["calc_frequency"] || drush_get_option('force', FALSE)) {
  41. $count = $info['calc_items'] - $info['running_items'];
  42. if ($count <= 0) {
  43. drush_log(dt("Maximum number of tasks (@count) already running.", array('@count' => $info['running_items'])));
  44. }
  45. else {
  46. drush_log(dt("Found @running running tasks, starting @count out of @max items.",
  47. array(
  48. '@running' => $info['running_items'],
  49. '@count' => $count,
  50. '@max' => $info['calc_items'])
  51. )
  52. );
  53. drush_invoke_process('@self', "hosting-" . $queue, array(), array('items' => $count, 'strict' => FALSE), array('fork' => TRUE));
  54. }
  55. }
  56. else {
  57. drush_log(dt("Too early for queue @queue.", array('@queue' => $queue)));
  58. }
  59. }
  60. else {
  61. drush_log(dt("Queue @queue disabled.", array('@queue' => $queue)));
  62. }
  63. drush_log(dt('Releasing @queue lock.', array('@queue' => $queue)));
  64. lock_release($semaphore);
  65. }
  66. }
  67. else {
  68. drush_log(dt("Dispatching disabled."));
  69. }
  70. }