Task¶
-
class
DANE.
Task
(key, priority=1, _id=None, api=None, state=None, msg=None, created_at=None, updated_at=None, **kwargs)¶ Class representation of a task, contains task information and has logic for interacting with DANE-server through a
base_classes.base_handler
Parameters: - key (str) – Key of the task, should match a binding key of a worker
- priority (int) – Priority to give to this task in queue. Defautls to 1.
- _id (int, optional) – id assigned by DANE-server to this task
- api (
base_classes.base_handler
, optional) – Reference to abase_classes.base_handler
which is used to communicate with the database, and queueing system. - state (int, optional) – Status code representing task state
- msg (str, optional) – Textual message accompanying the state
- created_at – Creation date
- updated_at – Last modified date
- **kwargs – Arbitrary keyword arguments. Will be stored in task.args
-
apply
(fn)¶ Applies fn to self
Parameters: fn (function) – Function handle in the form fn(task) Returns: self
-
assign
(document_id)¶ Assign a task to a document, this will set an _id for the task and run it. Requires an API to be set.
Parameters: document_id – id of document to assign this task to. Returns: self
-
assignMany
(document_ids)¶ Assign this task to multiple documents and run it. Requires an API to be set.
-
delete
()¶ Delete this task, requires it to be registered
Returns: bool
-
static
from_json
(task_str)¶ Constructs a
DANE.Task
instance from a JSON stringParameters: task_str (str or dict) – Serialised DANE.Task
Returns: An initialised Task Return type: DANE.Task
-
isDone
()¶ Check if this task has been completed.
A task is completed if it’s state equals 200. This will consult the API if the state isn’t set.
Returns: Task doneness Return type: bool
-
refresh
()¶ Retrieves the latest information for task state and msg which might have changed their values since the creation of this task. Requires an API to be set
Returns: self
-
reset
()¶ Reset the task state to 201
This can be used to force tasks to re-run after a preceding task has completed. Typically, the preceding task will be retried with force=True.
Returns: self
-
retry
(force=False)¶ Try to run this task again. Unlike
run()
this will attempt to run even after an error state was encountered.Parameters: force (bool, optional) – Force task to rerun regardless of previous state Returns: self
-
run
()¶ Run this task, requires it to be registered
Returns: self
-
set_api
(api)¶ Set the API for this task
Parameters: api ( base_classes.base_handler
, optional) – Reference to abase_classes.base_handler
which is used to communicate with the database, and queueing system.Returns: self
-
state
()¶ Get task state of this task.
Returns: Task state Return type: int
-
to_json
(indent=None)¶ Returns this task serialised as JSON
Returns: JSON serialisation of the task Return type: str