Jobs¶
A Job represents a specific execution of a task. To make an analogy with Python,
a Task gets instantiated into many Job, like a class that gets instantiated
into many objects.
Job¶
-
class
spinach.job.Job¶ Represent the execution of a
Taskby background workers.The
Jobclass should not be instantiated by the user, instead jobs are automatically created when they are scheduled.Variables: - id – UUID of the job
- status –
JobStatus - task_name – string name of the task
- queue – string name of the queue
- at – timezone aware datetime representing the date at which the job should start
- max_retries – int representing how many times a failing job should be retried
- retries – int representing how many times the job was already executed
- task_args – optional tuple containing args passed to the task
- task_kwargs – optional dict containing kwargs passed to the task
Job Status¶
-
class
spinach.job.JobStatus¶ Possible status of a
Job.Life-cycle:
- Newly created jobs first get the status NOT_SET
- Future jobs are then set to WAITING until they are ready to be QUEUED
- Jobs starting immediately get the status QUEUED directly when they are received by the broker
- Jobs are set to RUNNING when a worker start their execution
- if the job terminates without error it is set to SUCCEEDED
- if the job terminates with an error and can be retried it is set to WAITING until it is ready to be queued again
- if the job terminates with an error and cannot be retried it is set to FAILED for ever
See Signals to be notified on some of these status transitions.
-
FAILED= 5¶ Job failed and will not be retried
-
NOT_SET= 0¶ Job created but not scheduled yet
-
QUEUED= 2¶ Job is in a queue, ready to be picked by a worker
-
RUNNING= 3¶ Job is being executed
-
SUCCEEDED= 4¶ Job is finished, execution was successful
-
WAITING= 1¶ Job is scheduled to start in the future