@@ -723,10 +723,60 @@ function hosting_task_set_title(&$node) {
723
723
function hosting_tasks_queue($count = 20) {
724
724
global $provision_errors;
725
725
726
- drush_log(dt("Running tasks queue"));
727
726
$tasks = _hosting_get_new_tasks($count);
727
+
728
+ if (count($tasks)) {
729
+ drush_log(dt("Found @count tasks (max @max) in queue. Running...", array(
730
+ '@count' => count($tasks),
731
+ '@max' => $count,
732
+ )), "notice");
733
+ }
734
+ else {
735
+ drush_log(dt("Found no tasks in queue. Not running."), "notice");
736
+ }
737
+
728
738
foreach ($tasks as $task) {
729
- drush_invoke_process('@self', "hosting-task", array($task->nid), array('strict' => FALSE), array('fork' => TRUE));
739
+ hosting_task_execute($task, array('fork' => TRUE));
740
+ }
741
+ }
742
+
743
+ /**
744
+ * Executes a task while logging to watchdog and drush.
745
+ *
746
+ * @param $task
747
+ * A fully loaded task node.
748
+ */
749
+ function hosting_task_execute($task, $backend_options = array()) {
750
+ // Log in watchdog and drush.
751
+ watchdog('hosting_task', 'Starting task "@title" [node/@nid].', array(
752
+ '@title' => $task->title,
753
+ '@nid' => $task->nid,
754
+ ), WATCHDOG_NOTICE, url("node/$task->nid"));
755
+ drush_log(dt('Starting task "@title" [node/@nid].', array(
756
+ '@title' => $task->title,
757
+ '@nid' => $task->nid,
758
+ )), 'ok');
759
+
760
+ // Execute in it's own process.
761
+ drush_invoke_process('@self', "hosting-task", array($task->nid), array('strict' => FALSE), $backend_options);
762
+
763
+ // Log a message, depending on forked process or not.
764
+ // If forked, the process may not have completed yet, so we should change the message.
765
+ if ($backend_options['fork']) {
766
+ drush_log(dt('Launched task "@title" in a forked process. [node/@nid]', array(
767
+ '@title' => $task->title,
768
+ '@nid' => $task->nid,
769
+ )), 'ok');
770
+ }
771
+ // If not forked, load and display the task status.
772
+ else {
773
+ $task = node_load($task->nid, NULL, TRUE);
774
+ drush_log(dt('Finished task "@title" with status "@status" in @duration [node/@nid].', array(
775
+ '@title' => $task->title,
776
+ '@nid' => $task->nid,
777
+ '@status' => _hosting_parse_error_code($task->task_status),
778
+ '@duration' => format_interval($task->delta, 1),
779
+ )), 'ok');
730
780
}
731
781
}
732
782
0 commit comments