Skip to content

Latest commit

 

History

History
86 lines (62 loc) · 5.75 KB

cbq-model.md

File metadata and controls

86 lines (62 loc) · 5.75 KB
description
This model is provided to make certain tasks easier when defining and dispatching jobs, chains, and batches.

cbq Model

dispatch

Dispatches a job or chain of jobs.

ArgumentsTypeRequiredDefaultDescription
jobstring | Job | array<Job>trueA 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.
propertiesstructfalse{}A struct of properties for the Job instance.
chainarray<Job>false[]An array of Jobs to chain after this Job.
queuestringfalseThe queue the Job belongs to.
connectionstringfalseThe Connection to dispatch the Job on.
backoffnumericfalseThe amount of time, in seconds, to wait between attempting Jobs.
timeoutnumericfalseThe amount of time, in seconds, to wait before treating a Job as erroring.
maxAttemptsnumericfalseThe 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"
);

job

Creates a job or chain of jobs to be dispatched.

ArgumentsTypeRequiredDefaultDescription
jobstring | Job | array<Job>trueA 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.
propertiesstructfalse{}A struct of properties for the Job instance.
chainarray<Job>false[]An array of Jobs to chain after this Job.
queuestringfalseThe queue the Job belongs to.
connectionstringfalseThe Connection to dispatch the Job on.
backoffnumericfalseThe amount of time, in seconds, to wait between attempting Jobs.
timeoutnumericfalseThe amount of time, in seconds, to wait before treating a Job as erroring.
maxAttemptsnumericfalseThe 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();

chain

Creates a chain of jobs to be ran.

Alias for calling firstJob.chain( otherJobs ).

ArgumentsTypeRequiredDefaultDescription
jobsarray<Job>trueThe 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()

batch

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 %}

ArgumentsTypeRequiredDefaultDescription
jobsarray<Job>trueAn 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();