cbq
2.0.0
2.0.0
  • Home
  • What's New?
  • Getting Started
    • Installation
    • Walkthrough
  • Configuration
    • Module Settings
    • Config File
      • Queue Connection
      • Worker Pool
    • Providers
      • SyncProvider
      • ColdBoxAsyncProvider
      • DBProvider
  • Jobs
    • Defining a Job
    • Creating a Job
    • Dispatching a Job
    • Working a Job
    • Failed Jobs
    • Chained Jobs
    • Batched Jobs
  • cbq Model
  • Other
    • Contributing
    • Contributors
    • Prior Art
    • Dedication
Powered by GitBook
On this page
  • Dispatching
  • Interception Points
  • onCBQJobAdded
  1. Jobs

Dispatching a Job

PreviousCreating a JobNextWorking a Job

Last updated 1 year ago

Dispatching

Creating a Job is all well and good, but the Job will not be executed until it is dispatched on to a .

If you have a Job instance, you can dispatch it by calling the dispatch method.

component {

    function index( event, rc, prc ) {
        getInstance( "SendWelcomeEmailJob" );
            .setEmail( "john@example.com" );
            .setGreeting( "Welcome!" )
            .dispatch();
    }

}

You can also create and dispatch a job in the same call using the cbq.dispatch() method.

component {

    property name="cbq" inject="cbq@cbq";
    
    function index( event, rc, prc ) {
        cbq.dispatch(
            job = "SendWelcomeEmailJob",
            properties = {
                "email": "john@example.com",
                "greeting": "Welcome!"
            },
            chain = [],
            queue = "priority",
            connection = "db",
            backoff = 10,
            timeout = 30,
            maxAttempts = 3
        );
    }

}

Interception Points

onCBQJobAdded

This is fired before serializing a Job and sending it to a connection. The data includes the job to be serialized and dispatched and the connection the Job is being dispatched on.

variables.interceptorService.announce( "onCBQJobAdded", {
    "job" : job,
    "connection" : connection
} );
Queue Connection