cbq Model

This model is provided to make certain tasks easier when defining and dispatching jobs, chains, and batches.

dispatch

Dispatches a job or chain of jobs.

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.

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 ).

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.

To use batches, you must first configure a BatchRepository.

Learn more in the Batched Jobs documentation.

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();

Last updated