asynqueue.tasks.TaskHandler(object)
class documentation
Part of asynqueue.tasks
(View In Hierarchy)
I am a Queue handler that manages one or more providers of IWorker
.
When a new worker is hired with my hire
method,
I run the AssignmentFactory.request
method to request that the worker be assigned a task from the queue of each
task series for which it is qualified.
When the worker finally gets the assignment, it fires the Assignment
object's
internal deferred with a reference to itself. That is my cue to have the
worker run the assigned task and request another assignment of a task in
the same series when it's done, unless I've terminated the worker in the
meantime.
Each worker object maintains a dictionary of deferreds for each of its
outstanding assignment requests so that I can cancel them if I terminate
the worker. Then I can effectively cancel the assignment requests by firing
the deferreds with fake, no-task assignments. See my terminate
method.
Instance Variable | workers | A dict of worker objects that are currently employed by me,
keyed by a unique integer ID code for each worker. |
Method | __init__ | Undocumented |
Method | shutdown | Shutdown all my workers, then fire them, in turn. |
Method | hire | Adds a new worker to my work force. |
Method | terminate | Removes a worker from my work force, canceling all of its unfullfilled
assignment requests back from the queue and then attempting to shut it down
gracefully via its stop method. |
Method | roster | Returns a list of the workers who are qualified to run the specified series, or all my workers if no series specified. |
Method | update | No summary |
Method | __call__ | Generates a new assignment for the supplied task. This is the
handler for an item of base.Queue . |
dict
of worker objects that are currently employed by me,
keyed by a unique integer ID code for each worker.
Shutdown all my workers, then fire them, in turn.
Returns | A Deferred that fires when my entire work force has been
terminated. The deferred result is a list of all tasks, if any, that were
left unfinished by the work force. |
Adds a new worker to my work force.
Makes sure that there is an assignment request queue for each task series for which the worker is qualified, then has the new worker request an initial assignment from each queue.
The method generates an integer ID uniquely identifying the worker, and gives the worker an ID attribute with the ID for its own reference.
Returns | A Deferred that fires with the worker's ID when it has been
hired and is ready for assignments. |
Removes a worker from my work force, canceling all of its unfullfilled
assignment requests back from the queue and then attempting to shut it down
gracefully via its stop
method.
The timeout keyword can be set to a number of seconds after which
the worker will be terminated rudely via its crash
method if
it hasn't shut down gracefully by then. If the crash keyword is set
True
, the worker is crashed right away without waiting for it
to run through its pending tasks.
Returns | A Deferred that fires when the worker has been removed,
gracefully or not, with a list of any tasks left unfinished and not
reassigned. |
Returns a list of the workers who are qualified to run the specified series, or all my workers if no series specified.
Updates my workforce with the supplied task, calling identical copies of each one directly (I have no need of or reference to TaskQueue) to all current workers who are qualified to run the task. Saves the task for sending to qualified new hires as well.
Returns a deferred that fires when when the task has run on all current workers, with a list of the results from each run. Note that there is no mechanism for obtaining such results for new hires, so it's probably best not to rely too much on them.
If you don't want the task saved to the update list, but only run on my
current workers, set the ephemeral to True
.
Generates a new assignment for the supplied task. This is the
handler for an item of base.Queue
.
If the worker that runs the task is still working for me when it becomes ready for another task following this one, an assignment request will be entered for it to obtain another task of the same series.
Returns | A Deferred that fires when the task has been assigned to a
worker and it has accepted the assignment. |