One unit of background work in the platform's asynchronous job queue, such as an import, an export or a bulk update. A job records the task to run, a serialised input payload and a priority in which a lower number is processed first. A queue processor claims the job by setting the taken date, then eventually sets either the completed date or the cancelled date; a job with neither is still outstanding. Large jobs are split into sub jobs that point back at the parent through parentTask, and only root jobs, meaning those with no parent, are listed in the admin job views. Queries are filtered by cluster version so a job queued by one release is not picked up by another, and progress text lives on a separate AsyncJobStatus row rather than on the job itself.
Group: Database Entities
Implements: Serializable
Properties
| Property | Returns | Description |
|---|---|---|
| cancelled | boolean | Whether the job was cancelled rather than allowed to run to completion. |
| cancelledDate | Date | When the job was cancelled. A cancelled job counts as complete for the purposes of isComplete and of the queue, but it never produced a result. |
| clusterVersion | String | The cluster release this job is meant to run on. Queue queries filter on it, so a processor on the default cluster picks up jobs matching its own version or with no version at all, and a processor on any other cluster picks up only exact matches. |
| complete | boolean | Whether the job has reached a final state, either by completing or by being cancelled. |
| completedDate | Date | When the job finished. A job with neither a completed date nor a cancelled date is still outstanding. |
| createdDate | Date | When the job was added to the queue. Job listing and reporting filter on this, and jobs of equal priority are processed oldest first. Required. |
| id | long | Database identifier of this job, assigned when the row is first saved. |
| incomplete | boolean | Whether the job is still outstanding, meaning it has neither completed nor been cancelled. A job that has been taken by a processor but has not finished is still incomplete. |
| jobInput | String | The serialised task payload the job was queued with, which is what the processor deserialises to rebuild the work to do. Limited to 100000 characters, the same as DbAsyncProcessor.MAX_PAYLOAD_SIZE, and queueing a larger payload fails. |
| jobOutput | String | Whatever the job produced, held either as the content itself or as a hash pointing at stored content. Up to 100000 characters. |
| jobPriority | int | Queue priority, where a lower number is picked up first. Jobs of equal priority are processed oldest first. |
| jobStatus | AsyncJobStatus | The progress record for this job, which is where the running task writes its status text. Not a mapped column: it is looked up on every call, and it can be null for a job whose status record was never created. |
| parentTask | AsyncJob | The job this one was split off from. Only root jobs, meaning those with no parent, are listed in the admin job views and counted as jobs in their own right. |
| runAs | Profile | The profile the task runs as, so the work is done with that user's permissions rather than with no user at all. Optional. |
| runBy | Profile | The profile that queued this job, when it was started by someone in the admin rather than by the system. Optional. |
| subJobs | List<AsyncJob> | The jobs this one was split into. Not a mapped column: it queries for the sub jobs on every call using the current session. |
| takenDate | Date | When a queue processor claimed this job. take sets it under a pessimistic write lock so that only one processor in the cluster can claim a given job. |
| taskName | String | Name of the task to run, matching the registered TrackedProcessable that knows how to run it. Sub jobs created by createSubJob have no task name, because they carry only an input payload for the parent's task. |
| warnings | String | Warning messages produced while the job ran, separated by newlines. These do not stop the job completing, so a job can finish successfully and still carry warnings. |
Methods
getId() · getRunAs() · getRunBy() · getParentTask() · getTaskName() · getCreatedDate() · getTakenDate() · getCompletedDate() · getCancelledDate() · getWarnings() · getJobInput() · getJobOutput() · getJobPriority() · getClusterVersion() · getSubJobs() · durationSubJobsMillis() · durationSubJobsMillis(List<AsyncJob> subJobs) · effectiveDuration() · isIncomplete() · isComplete() · getJobStatus() · isCancelled() · statusText()
getId()
Returns: long
Database identifier of this job, assigned when the row is first saved.
getRunAs()
Returns: Profile
The profile the task runs as, so the work is done with that user's permissions rather than with no user at all. Optional.
getRunBy()
Returns: Profile
The profile that queued this job, when it was started by someone in the admin rather than by the system. Optional.
getParentTask()
Returns: AsyncJob
The job this one was split off from. Only root jobs, meaning those with no parent, are listed in the admin job views and counted as jobs in their own right.
getTaskName()
Returns: String
Name of the task to run, matching the registered TrackedProcessable that knows how to run it. Sub jobs created by createSubJob have no task name, because they carry only an input payload for the parent's task.
getCreatedDate()
Returns: Date
When the job was added to the queue. Job listing and reporting filter on this, and jobs of equal priority are processed oldest first. Required.
getTakenDate()
Returns: Date
When a queue processor claimed this job. take sets it under a pessimistic write lock so that only one processor in the cluster can claim a given job.
getCompletedDate()
Returns: Date
When the job finished. A job with neither a completed date nor a cancelled date is still outstanding.
getCancelledDate()
Returns: Date
When the job was cancelled. A cancelled job counts as complete for the purposes of isComplete and of the queue, but it never produced a result.
getWarnings()
Returns: String
Warning messages produced while the job ran, separated by newlines. These do not stop the job completing, so a job can finish successfully and still carry warnings.
getJobInput()
Returns: String
The serialised task payload the job was queued with, which is what the processor deserialises to rebuild the work to do. Limited to 100000 characters, the same as DbAsyncProcessor.MAX_PAYLOAD_SIZE, and queueing a larger payload fails.
getJobOutput()
Returns: String
Whatever the job produced, held either as the content itself or as a hash pointing at stored content. Up to 100000 characters.
getJobPriority()
Returns: int
Queue priority, where a lower number is picked up first. Jobs of equal priority are processed oldest first.
getClusterVersion()
Returns: String
The cluster release this job is meant to run on. Queue queries filter on it, so a processor on the default cluster picks up jobs matching its own version or with no version at all, and a processor on any other cluster picks up only exact matches.
getSubJobs()
Returns: List<AsyncJob>
The jobs this one was split into. Not a mapped column: it queries for the sub jobs on every call using the current session.
durationSubJobsMillis()
Returns: long
Total time in milliseconds spent running this job's sub jobs, counting only those that have finished or been cancelled. Runs a query for the sub jobs.
durationSubJobsMillis(List<AsyncJob> subJobs)
Returns: long
Total time in milliseconds spent running this job's sub jobs, counting only those that have finished or been cancelled. The given list is not used: the method re-reads the sub jobs from the database itself, so it always reports on the current sub jobs.
| Parameter | Description |
|---|---|
subJobs | the sub jobs to total, ignored by the current implementation |
effectiveDuration()
Returns: long
How long this job really took, in milliseconds. For a job with no sub jobs that is the time between it being taken and it finishing. For a job that was split up the parent's own elapsed time is ignored, because the parent only splits the work, so the total sub job time is reported instead.
isIncomplete()
Returns: boolean
Whether the job is still outstanding, meaning it has neither completed nor been cancelled. A job that has been taken by a processor but has not finished is still incomplete.
isComplete()
Returns: boolean
Whether the job has reached a final state, either by completing or by being cancelled.
getJobStatus()
Returns: AsyncJobStatus
The progress record for this job, which is where the running task writes its status text. Not a mapped column: it is looked up on every call, and it can be null for a job whose status record was never created.
isCancelled()
Returns: boolean
Whether the job was cancelled rather than allowed to run to completion.
statusText()
Returns: String
The progress message last written by the running task, for showing job progress in the admin. Looks up the job's status record, so it costs a query.