Let the platform do the work

Application Schedulers

Overview

Application Scheduler extensions add custom functions that can be used by scheduler jobs.

Note: This Extension is a duplicate of the ScheduledTasks extension, which typically places Scheduled Tasks in the Schedulers directory.

Properties

The following extension properties are available. For more information, please refer to the Extension Property documentation.

Property Value
Extension Scope Application
Sugar Variable $job_strings
Extension Directory ./custom/Extension/application/Ext/ScheduledTasks/
Compiled Extension File ./custom/application/Ext/ScheduledTasks/scheduledtasks.ext.php
Manifest Installdef $installdefs['appscheduledefs']

Implementation

The following sections illustrates the various ways to implement a customization to a Sugar instance.

File System

When working directly with the filesystem, you can create a file in ./custom/Extension/application/Ext/ScheduledTasks/ to add a new Scheduler Task to the system. The following example will create a new Scheduler Task 'example_job':

./custom/Extension/application/Ext/ScheduledTasks/<file>.php

<?php

$job_strings[] = 'exampleJob';

function exampleJob()
{
    //logic here

    //return true for completed
    return true;
}

Next create the Language file for the Scheduler, so that the Job properly displays in Admin > Schedulers section:

./custom/Extension/modules/Schedulers/Ext/Language/<language>.<file>.php

<?php
//Label will be LBL_[upper case function name]
$mod_strings['LBL_EXAMPLEJOB'] = 'Example Job';

Next, navigate to Admin > Repair > Quick Repair and Rebuild. The system will then rebuild the extensions and the customizations will be compiled into ./custom/application/Ext/ScheduledTasks/scheduledtasks.ext.php

Module Loadable Package

When building a module loadable package, you can use the $installdefs['appscheduledefs'] index to install the extension file.

Installdef Properties

Name Type Description
from String The base path of the file to be installed.

The example below demonstrates the proper install definition that should be used in the ./manifest.php file in order to add the custom Scheduler definition file to the system. You should note that, when using this approach, Sugar will automatically execute Rebuild Extensions to reflect the new scheduler in the system.

./manifest.php

<?php

$manifest = array(
    ...
);

$installdefs = array(
    'id' => 'appScheduledTasks_example',
    'appscheduledefs' => array(
        array(
            'from' => '<basepath>/Files/custom/Extension/application/Ext/ScheduledTasks/<file>.php',
        )
    ),
    'language' => array(
        array(
            'from' =>'<basepath>/Files/custom/Extension/modules/Schedulers/Ext/Language/<file>.php',
            'to_module' => 'Schedulers',
            'language' => 'en_us'
        )
    )
);

Alternatively, you may use the $installdefs['copy'] index for the Scheduled Task Extension file. When using this approach, you may need to manually run a repair action such as a Quick Repair and Rebuild.

For more information about the $installdefs['copy'] index and module-loadable packages, please refer to the Introduction to the Manifest page.

Topics