Creating Custom Schedulers
Overview
In addition to the default schedulers that are packaged with Sugar, developers can create custom scheduler jobs.
Defining the Job Label
The first step to create a custom scheduler is creating a label extension file. This will add the display text for the scheduler job when creating a new scheduler in Admin > Scheduler. The file path of our file will be in the format of ./custom/Extension/modules/Schedulers/Ext/Language/<language key>.<name>.php
. For our example, name the file en_us.custom_job.php
.
./custom/Extension/modules/Schedulers/Ext/Language/en_us.custom_job.php
<?php
$mod_strings['LBL_CUSTOM_JOB'] = 'Custom Job';
Defining the Job Function
Next, define the custom job's function using the extension framework. The file path of the file will be in the format of ./custom/Extension/modules/Schedulers/Ext/ScheduledTasks/<function_name>.php
. For this example, name the file custom_job.php
. Prior to 6.3.x, job functions were added by creating the file ./custom/modules/Schedulers/_AddJobsHere.php
. This method of creating functions is still compatible but is not recommended from a best practices standpoint.
./custom/Extension/modules/Schedulers/Ext/ScheduledTasks/custom_job.php
<?php
array_push($job_strings, 'custom_job');
function custom_job()
{
//logic here
//return true for completed
return true;
}
Using the New Job
Once the files are in place, navigate to Admin > Repair > Quick Repair and Rebuild. This will rebuild the extension directories with our additions. Next, navigate to Admin > Scheduler > Create Scheduler. In the Jobs dropdown, there will be a new custom job in the list.