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:
- Adds a
hook_post_hosting_task()invocation right beforehook_post_hosting_TYPE_task(). - Adds a implementation of that hook to hosting_task.drush.inc.
- 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.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | 2446749-hosting-task-hooks-2.x.patch | 3.3 KB | jon pugh |
| #1 | 2446749-hosting-task-hooks.patch | 2.07 KB | jon pugh |
| #3 | 2446749-hosting-task-hooks.patch | 2.69 KB | jon pugh |
Comments
Comment #1
jon pughPatch attached.
Comment #2
jon pughOk, 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_statusjust for us.stand by
Comment #3
jon pughNew patch attached.
New approach:
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.
Comment #4
helmo commentednice, please add the api files and get it committed.
Comment #5
ergonlogicI'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.
Comment #6
helmo commentedneeds api documentation... as per #3
Comment #7
jon pughOn it right now.
Comment #8
jon pughPushed to branch ' issue-2446749-hosting-task-status'.
Can I get an RTBC?
Comment #9
ergonlogicAPI docs are nicely descriptive. +1
Comment #10
jon pughCommitted and backported.
Thanks!