The current method for updating a task's status makes it so you can never really hook into a task success.

hosting_task.drush.inc:

/**
 * Implements hook_drush_init().
 */
function hosting_task_drush_init() {
  // Update a task's status after Drush operations are complete.
  if (function_exists('_hosting_task_update_status')) {
    register_shutdown_function('_hosting_task_update_status');
  }
}

Since the status is never saved until "shutdown", When I try to add a drush hook for hook_post_hosting_TYPE_task(), no matter what I do, the task_status is still Processing.

I do not think I should have to register a shutdown function to react to a successful task.

I have refactored hosting_task.drush.inc, hosting_task.module, and task.hosting.inc:

I made the following changes:

  1. Adds a hook_post_hosting_task() invocation right before hook_post_hosting_TYPE_task().
  2. Adds a implementation of that hook to hosting_task.drush.inc.
  3. Removes the unneeded helper function _hosting_task_update_status()

This now makes it much more clear where the task status is getting saved, and allows modules to react to any task_status.

Comments

jon pugh’s picture

StatusFileSize
new2.07 KB

Patch attached.

jon pugh’s picture

Ok, I understand more now. :)

The register_shutdown is needed to catch the task no matter what drush does.

I have refactored again to create a new hook within hosting_task_update_status just for us.

stand by

jon pugh’s picture

New patch attached.

New approach:

  • New register_shutdown_function: hosting_task_drush_update_status()
  • hosting_task_drush_update_status() is based on _hosting_task_update_status() function and is added to hosting_task.drush.inc.
  • hosting_task_update_status() is altered. $task is no longer optional, and the lookup for the task drush context is removed, in favor of doing it in hosting_task_drush_update_status()
  • Changed the $update variable to $status to be more clear what it is.
  • Added a module_invoke_all('hosting_task_update_status', $task, $status);

I decided not to add a new hook `hook_post_hosting_task` since I think both this and 'hook_post_hosting_%s_task' should be deprecated in favor of `hook_hosting_task_update_status();`

Also attached is a backported patch for 6.x-2.x. I think it deserves to get backported because it handles the data in exactly the same way, and adds functionality that was previously impossible to use: Easily responding to task success and errors with a single hook.

Only next steps is to add to the API files.

helmo’s picture

nice, please add the api files and get it committed.

ergonlogic’s picture

I'd added the shutdown function as a stop-gap, because we were reporting tasks as successful, despite failures in post_task hooks. This appears to add some nice flexibility.

helmo’s picture

Status: Needs review » Needs work

needs api documentation... as per #3

jon pugh’s picture

Assigned: Unassigned » jon pugh
Status: Needs work » Active

On it right now.

jon pugh’s picture

Status: Active » Needs review

Pushed to branch ' issue-2446749-hosting-task-status'.

Can I get an RTBC?

ergonlogic’s picture

Status: Needs review » Reviewed & tested by the community

API docs are nicely descriptive. +1

jon pugh’s picture

Status: Reviewed & tested by the community » Fixed

Committed and backported.

Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.