Defining a Job
Last updated
component
name="SendWelcomeEmailJob"
extends="cbq.models.Jobs.AbstractJob"
{
property name="mailService" inject="provider:MailService@cbmailservices";
property name="email";
property name="greeting";
function handle() {
variables.mailService.newMail(
to = variables.email,
from = "noreply@example.com",
subject = "Welcome!",
type = "html",
bodyTokens = {
"greeting": variables.greeting
"link": getInstance( "coldbox:requestContext" )
.buildLink( "home" )
}
)
.setView( "_emails/welcome" )
.send();
}
}component extends="cbq.models.Jobs.AbstractJob" {
// Name of the connection to dispatch this job on.
variables.connection = "db";
// Name of the queue to use for this job.
variables.queue = "priority";
// Time, in seconds, between job attempts, including the initial attempt.
variables.backoff = 15;
// Time, in seconds, to let a job run before failing it.
variables.timeout = 30;
// Max number of attempts before marking a job as failed.
// Use 0 for unlimited retries.
variables.maxAttempts = 9;
}component
name="SendWelcomeEmailJob"
extends="cbq.models.Jobs.AbstractJob"
{
property name="mailService" inject="provider:MailService@cbmailservices";
property name="email";
property name="greeting";
function handle() {
variables.mailService.newMail(
to = variables.email,
from = "noreply@example.com",
subject = "Welcome!",
type = "html",
bodyTokens = {
"greeting": variables.greeting
"link": getInstance( "coldbox:requestContext" )
.buildLink( "home" )
}
)
.setView( "_emails/welcome" )
.send();
}
function before() {
log.debug( "About to execute SendWelcomeEmailJob" );
}
function after() {
log.debug( "Finished executing SendWelcomeEmailJob" );
}
}