job queue

To add a job to the job queue using a logic hook.

Within the logic hook you should add something like the following.



// First, let's create the new job
$job = new SchedulersJob();
$job->name = "Account Alert Job - {$bean->name}";
$job->data = $bean->id;   // key piece, this is data we are passing to the job that it can use to run it.
$job->target = "function::CustomerAlert";   // class that has the job to run; implements RunnableSchedulerJob

// Now push into the queue to run
$date_time = DateTime::createFromFormat("Y-m-d H:i:s", $timedate->nowDb());
$date_time = $date_time->add(new DateInterval('PT5M'));

$job->assigned_user_id = $current_user->id;
$job->execute_time = $date_time->format("Y-m-d H:i:s");
$jq = new SugarJobQueue();
$jobid = $jq->submitJob($job);


You will need to make sure that there is a job for the function CustomerAlert for the example above.