Skip to content

Commit 05f49c3

Browse files
jonpughhelmo
authored andcommitted
Issue #2828630: More verbose drush logs for drush hosting-tasks command
1 parent c82295d commit 05f49c3

File tree

2 files changed

+60
-7
lines changed

2 files changed

+60
-7
lines changed

queued/hosting_queued.drush.inc

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function drush_hosting_queued() {
6262
variable_set('hosting_queued_process_started', REQUEST_TIME);
6363

6464
watchdog('hosting_queued', 'Started Hosting queue daemon, waiting for new tasks');
65-
65+
drush_log('Started hosting queue daemon. Waiting for new tasks.', 'ok');
6666
while (TRUE) {
6767
try {
6868
// Should we terminate.
@@ -74,6 +74,11 @@ function drush_hosting_queued() {
7474

7575
// Get some tasks to run
7676
if ($tasks = @_hosting_get_new_tasks()) {
77+
78+
drush_log(dt("Found %count tasks in queue. Running...", array(
79+
'%count' => count($tasks),
80+
)), "notice");
81+
7782
if (lock_acquire('hosting_queue_tasks_running', HOSTING_QUEUE_LOCK_TIMEOUT)) {
7883
drush_log('Acquired lock on task queue.');
7984
foreach ($tasks as $task) {
@@ -85,10 +90,8 @@ function drush_hosting_queued() {
8590
drush_log(dt('Found task to execute. Pausing before execution.'));
8691
sleep(1);
8792

88-
watchdog('hosting_queued', 'Running task @nid.', array('@nid' => $task->nid));
89-
// Execute the task in the backend
90-
drush_invoke_process('@self', 'hosting-task', array($task->nid), array('strict' => FALSE), array('interactive' => TRUE));
91-
drush_log(dt('Finished executing task.'));
93+
// Execute the task.
94+
hosting_task_execute($task, array('interactive' => TRUE));
9295

9396
// Delay for a configurable amount of time.
9497
$delay = variable_get('hosting_queued_post_task_delay', 0);

task/hosting_task.module

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -723,10 +723,60 @@ function hosting_task_set_title(&$node) {
723723
function hosting_tasks_queue($count = 20) {
724724
global $provision_errors;
725725

726-
drush_log(dt("Running tasks queue"));
727726
$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+
728738
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');
730780
}
731781
}
732782

0 commit comments

Comments
 (0)