Bases: object
A Job is a task to execute.
When the job is enqueued, UUID of the worker.
State of the job, can pending, enqueued, started, done or failed. The start state is pending and the final state is done.
The current try, starts at 0 and each time the job is executed, it increases by 1.
The maximum number of retries allowed before the job is considered as failed.
Name of the function (in the form module.function_name).
Arguments passed to the function when executed.
Keyword arguments passed to the function when executed.
Full string representing the function to be executed, ie. module.function(args, kwargs)
OpenERP model on which the job will run.
Priority of the job, 0 being the higher priority.
Date and time when the job was created.
Date and time when the job was enqueued.
Date and time when the job was started.
Date and time when the job was done.
A description of the result (for humans).
Exception information (traceback) when the job failed.
OpenERP user id which created the job
True if the job has been canceled.
Execute the job.
The job is executed with the user which has initiated it.
Parameters: | session (ConnectorSession) – session to execute the job |
---|
Write an estimated time arrival to n seconds later than now. Used when an retryable exception want to retry a job later.
Job ID, this is an UUID
Bases: connector.queue.job.JobStorage
Store a job on OpenERP
Create a Job and enqueue it in the queue. Return the job uuid.
This expects the arguments specific to the job to be already extracted from the ones to pass to the job function.
Decorator for jobs.
Add a delay attribute on the decorated function.
When delay is called, the function is transformed to a job and stored in the OpenERP queue.job model. The arguments and keyword arguments given in delay will be the arguments used by the decorated function when it is executed.
The delay() function of a job takes the following arguments:
Arguments and keyword arguments which will be given to the called function once the job is executed. They should be pickle-able.
There is 4 special and reserved keyword arguments that you can use:
- priority: priority of the job, the smaller is the higher priority.
Default is 10.
- max_retries: maximum number of retries before giving up and set
the job state to ‘failed’. A value of 0 means infinite retries. Default is 5.
- eta: the job can be executed only after this datetime
(or now + timedelta if a timedelta or integer is given)
- description : a human description of the job,
intended to discriminate job instances (Default is the func.__doc__ or
‘Function %s’ % func.__name__)
Example:
@job
def export_one_thing(session, model_name, one_thing):
# work
# export one_thing
export_one_thing(session, 'a.model', the_thing_to_export)
# => normal and synchronous function call
export_one_thing.delay(session, 'a.model', the_thing_to_export)
# => the job will be executed as soon as possible
export_one_thing.delay(session, 'a.model', the_thing_to_export,
priority=30, eta=60*60*5)
# => the job will be executed with a low priority and not before a
# delay of 5 hours from now
See also: related_action() a related action can be attached to a job
Attach a Related Action to a job.
A Related Action will appear as a button on the OpenERP view. The button will execute the action, usually it will open the form view of the record related to the job.
The action must be a callable that responds to arguments:
session, job, **kwargs
Example usage:
def related_action_partner(session, job):
model = job.args[0]
partner_id = job.args[1]
# eventually get the real ID if partner_id is a binding ID
action = {
'name': _("Partner"),
'type': 'ir.actions.act_window',
'res_model': model,
'view_type': 'form',
'view_mode': 'form',
'res_id': partner_id,
}
return action
@job
@related_action(action=related_action_partner)
def export_partner(session, model_name, partner_id):
# ...
The kwargs are transmitted to the action:
def related_action_product(session, job, extra_arg=1):
assert extra_arg == 2
model = job.args[0]
product_id = job.args[1]
@job
@related_action(action=related_action_product, extra_arg=2)
def export_product(session, model_name, product_id):
# ...
Bases: threading.Thread
Post and retrieve jobs from the queue, execute them
Enqueue a job:
It will be executed by the worker as soon as possible (according to the job’s priority
alias of OpenERPJobStorage
alias of JobsQueue
Bases: threading.Thread
Keep a sight on the workers and signal their aliveness.
A WorkerWatcher is shared between databases, so only 1 instance is necessary to check the aliveness of the workers for every database.
Returns the databases for the server having the connector module installed.
Available means that they can be used by a Worker.
Returns: | database names |
---|---|
Return type: | list |
Bases: openerp.osv.orm.Model
Job status and result
Delete all jobs (active or not) done since more than _removal_interval days.
Called from a cron.
Open the related action associated to the job
Bases: openerp.osv.orm.Model
Worker
Assign n jobs to the worker of the current process
n is max_jobs or unlimited if max_jobs is None
Parameters: | max_jobs (int) – maximal limit of jobs to assign on a worker |
---|
Assign all the jobs not already assigned to a worker. Then enqueue all the jobs having a worker but not enqueued.
Each operation is atomic.
Warning
commit transaction cr.commit() is called, so please always call this method in your own transaction, not in the main OpenERP’s transaction
Parameters: | max_jobs (int) – maximal limit of jobs to assign on a worker |
---|
Enqueue all the jobs assigned to the worker of the current process