description |
---|
This model is provided to make certain tasks easier when defining and dispatching jobs, chains, and batches. |
Dispatches a job or chain of jobs.
Arguments | Type | Required | Default | Description | |
---|---|---|---|---|---|
job | string | Job | array<Job> | true | A Job instance or a WireBox ID of a Job instance. If the WireBox ID doesn't exist, a NonExecutableJob instance will be used instead. This allows you to dispatch a Job from a server where that Job component is not defined. If an array is passed, a Job Chain is created and dispatched. | ||
properties | struct | false | {} | A struct of properties for the Job instance. | |
chain | array<Job> | false | [] | An array of Jobs to chain after this Job. | |
queue | string | false | The queue the Job belongs to. | ||
connection | string | false | The Connection to dispatch the Job on. | ||
backoff | numeric | false | The amount of time, in seconds, to wait between attempting Jobs. | ||
timeout | numeric | false | The amount of time, in seconds, to wait before treating a Job as erroring. | ||
maxAttempts | numeric | false | The maximum amount of attempts of a Job before treating the Job as failed. |
Return: The dispatched Job instance.
cbq.dispatch(
job = "SendWelcomeEmailJob",
properties = { "body": "first body" },
queue = "default"
);
Creates a job or chain of jobs to be dispatched.
Arguments | Type | Required | Default | Description | |
---|---|---|---|---|---|
job | string | Job | array<Job> | true | A Job instance or a WireBox ID of a Job instance. If the WireBox ID doesn't exist, a NonExecutableJob instance will be used instead. This allows you to dispatch a Job from a server where that Job component is not defined. If an array is passed, a Job Chain is created and dispatched. | ||
properties | struct | false | {} | A struct of properties for the Job instance. | |
chain | array<Job> | false | [] | An array of Jobs to chain after this Job. | |
queue | string | false | The queue the Job belongs to. | ||
connection | string | false | The Connection to dispatch the Job on. | ||
backoff | numeric | false | The amount of time, in seconds, to wait between attempting Jobs. | ||
timeout | numeric | false | The amount of time, in seconds, to wait before treating a Job as erroring. | ||
maxAttempts | numeric | false | The maximum amount of attempts of a Job before treating the Job as failed. |
Return: The new Job instance.
cbq.job( "SendWelcomeEmailJob" )
.setProperties( { "body": "first body" } )
.onQueue( "default" )
.dispatch();
Creates a chain of jobs to be ran.
Alias for calling firstJob.chain( otherJobs )
.
Arguments | Type | Required | Default | Description | |
---|---|---|---|---|---|
jobs | array<Job> | true | The array of jobs to run in order in a chain. |
Return: The first job of the chain with the chained jobs configured to be dispatched.
cbq.chain( [
cbq.job( "SendWelcomeEmailJob", { "body": "One" }, [], "default" ),
cbq.job( "SendWelcomeEmailJob", { "body": "Two" }, [], "default", "sync" ),
cbq.job( "SendWelcomeEmailJob", { "body": "Three" }, [], "default" )
] )
.dispatch()
Creates a PendingBatch from the Jobs provided.
{% hint style="warning" %}
To use batches, you must first configure a BatchRepository
.
Learn more in the Batched Jobs documentation. {% endhint %}
Arguments | Type | Required | Default | Description | |
---|---|---|---|---|---|
jobs | array<Job> | true | An array of jobs to batch together. |
Return: The PendingBatch to be dispatched.
var batch = cbq
.batch( [
cbq.job( "ImportCsvJob", { "start": 1, "end": 100 } ),
cbq.job( "ImportCsvJob", { "start": 101, "end": 200 } ),
cbq.job( "ImportCsvJob", { "start": 201, "end": 300 } ),
cbq.job( "ImportCsvJob", { "start": 301, "end": 400 } ),
cbq.job( "ImportCsvJob", { "start": 401, "end": 500 } )
] )
.then( cbq.job( "ImportCsvSuccessfulJob" ) )
.catch( cbq.job( "ImportCsvFailedJob" ) )
.finally( cbq.job( "ImportCsvCompletedJob" ) )
.dispatch();