Add a callback mechanism to inject code globally into all tasks

Registered by Greg Hill

In some cases, you need a bit of code to run before or after every task to handle global state initialization and/or cleanup. As a specific example, if you're using global SQLAlchemy sessions within the worker process, you need to close the session after every task to insure you don't reuse a stale session in future tasks. To provide an easy way for consumers to inject their own code into the worker process, I am proposing we add the ability to inject callbacks at key parts of the process.

The following callbacks are suggested as an initial set:

pre_execute
post_execute
pre_revert
pre_revert

To accomplish this, methods of those names should be added to the Task object, with a default implementation of nothing. Subclasses can define their own methods and those will be invoked as part of the task execution process.

Blueprint information

Status:
Complete
Approver:
Joshua Harlow
Priority:
Medium
Drafter:
Greg Hill
Direction:
Needs approval
Assignee:
Greg Hill
Definition:
Approved
Series goal:
None
Implementation:
Implemented
Milestone target:
None
Started by
Joshua Harlow
Completed by
Joshua Harlow

Related branches

Sprints

Whiteboard

Gerrit topic: https://review.openstack.org/#q,topic:bp/task-callbacks,n,z

Addressed by: https://review.openstack.org/112300
    add pre/post execute/retry callbacks to tasks

(?)

Work Items

This blueprint contains Public information 
Everyone can see this information.

Subscribers

No subscribers.