gws.base.job.manager¶
Job manager.
Source code: gws.base.job.manager
Module Contents¶
- class gws.base.job.manager.Object¶
Bases:
gws.JobManagerJob manager.
- DDL = Multiline-String¶
Show Value
""" CREATE TABLE IF NOT EXISTS jobs ( uid TEXT NOT NULL PRIMARY KEY, userUid TEXT DEFAULT '', userStr TEXT DEFAULT '', worker TEXT DEFAULT '', state TEXT DEFAULT '', error TEXT DEFAULT '', numSteps INTEGER DEFAULT 0, step INTEGER DEFAULT 0, stepName TEXT DEFAULT '', payload TEXT DEFAULT '', result TEXT DEFAULT '', created INTEGER DEFAULT 0, updated INTEGER DEFAULT 0 ) """
DDL statement for the jobs table.
- TABLE = 'jobs'¶
Name of the jobs table.
- cancel_job(job: gws.Job) gws.Job | None¶
Set a job to the
cancelstate.The worker notices the change on its next job update and stops.
- Parameters:
job – The job.
- Returns:
The updated job, or
Noneif the job does not exist.
- configure()¶
Configuration hook.
Called when the node is initialized. Raising an exception here aborts the creation of the node.
- create_job(worker, user, payload=None)¶
Create a job in the
openstate.- Parameters:
worker – Worker class. It must have a
run(root, job)class method.user – User the job runs for.
payload – Input data for the worker, must be JSON-serializable.
- Returns:
The new job.
- get_job(job_uid: str, user=None, state=None)¶
Read a job.
- Parameters:
job_uid – Job uid.
user – If given, the job must belong to this user.
state – If given, the job must be in this state.
- Returns:
The job, or
Noneif it does not exist or does not match. The reason is logged.
- handle_cancel_request(req, p)¶
Cancel a job of the requesting user.
- Parameters:
req – Web request.
p – Job request.
- Returns:
The job status after cancelling.
- Raises:
gws.NotFoundError – If the job does not exist or belongs to another user.
- handle_status_request(req, p)¶
Return the status of a job of the requesting user.
- Parameters:
req – Web request.
p – Job request.
- Returns:
The job status.
- Raises:
gws.NotFoundError – If the job does not exist or belongs to another user.
- job_status_response(job, **kwargs)¶
Create a status response for a job.
- Parameters:
job – The job.
**kwargs – Extra or overriding response fields.
- Returns:
The status response.
- require_job(req, p)¶
Return the job of a request, if it belongs to the requesting user.
- Parameters:
req – Web request.
p – Job request.
- Returns:
The job.
- Raises:
gws.NotFoundError – If the job does not exist or belongs to another user.
- require_result(req, p)¶
Return the result of a completed job of the requesting user.
- Parameters:
req – Web request.
p – Job request.
- Returns:
The job result.
- Raises:
gws.NotFoundError – If the job does not exist, belongs to another user, is not complete or has no result.
- run_job(job: gws.Job)¶
Run an open job in the current process.
Marks the job as running, so that it runs only once, and calls the
runmethod of its worker. If the worker raises an exception, the job goes into theerrorstate.- Parameters:
job – The job.
- Returns:
The job after the run.
- Raises:
gws.Error – If the job is not open or is already taken by another process.
- schedule_job(job: gws.Job)¶
Start an open job.
The job is passed to the uWSGI spooler if it is available, otherwise it runs at once in the current process.
- Parameters:
job – The job.
- Returns:
The job.
- Raises:
gws.Error – If the job is not open.
- update_job(job, **kwargs)¶
Update fields of a job.
- Parameters:
job – The job.
**kwargs – Job fields to update.
- Returns:
The updated job, or
Noneif the job does not exist.