You are here

function hook_cronapi in Ultimate Cron 8.2

Same name and namespace in other branches
  1. 7.2 ultimate_cron.api.php \hook_cronapi()

Inform Ultimate Cron about cron jobs.

To add additional/multiple cron jobs from a custom module, provide a default configuration in the module with the needed settings. Example: ultimate_cron.job.custom_module_cron.yml

Note that the result of this hook is cached.

Return value

array Array of cron jobs, keyed by name.

  • "title": (optional) The title of the cron job. If not provided, the name of the cron job will be used.
  • "file": (optional) The file where the callback lives.
  • "module": The module where this job lives.
  • "file path": (optional) The path to the directory containing the file specified in "file". This defaults to the path to the module implementing the hook.
  • "callback": (optional) The callback to call when running the job. Defaults to the job name.
  • "callback arguments": (optional) Arguments for the callback. Defaults to array().
  • "enabled": (optional) Initial state of the job. Defaults to TRUE.
  • "tags": (optional) Tags for the job. Defaults to array().
  • "settings": (optional) Default settings (plugin type) for this job. Example of a job declaring some default settings for a plugin called "some_plugin": 'settings' => array( 'some_plugin' => array( 'some_value' => 60, ), ),
  • "scheduler": (optional) Default scheduler (plugin type) for this job. Example of a job using the crontab scheduler as default: 'scheduler' => array( 'name' => 'crontab', 'crontab' => array( 'rules' => array('* * * * *'), ), ),
  • "launcher": (optional) Default launcher (plugin type) for this job. Example of a job using the serial launcher as default: 'launcher' => array( 'name' => 'serial', 'serial' => array( 'thread' => 'any', ), ),
  • "logger": (optional) Default logger (plugin type) for this job. Example of a job using the cache logger as default: 'logger' => array( 'name' => 'cache', 'cache' => array( 'bin' => 'mycachebin', ), ),

File

./ultimate_cron.api.php, line 70
Hooks provided by Ultimate Cron.

Code

function hook_cronapi() {
  $items = array();
  $items['example_my_cron_job_1'] = array(
    'title' => t('This is my cron job #1'),
    'file' => 'example.jobs.inc',
    'file path' => drupal_get_path('module', 'example') . '/cron',
    'callback' => 'example_my_cron_job_callback',
    'callback arguments' => array(
      'cronjob1',
    ),
    'enabled' => FALSE,
    'tags' => array(
      'example',
    ),
    'settings' => array(
      'example_plugin' => array(
        'example_setting' => 'example_value',
      ),
    ),
    'scheduler' => array(
      'name' => 'crontab',
      'crontab' => array(
        'rules' => array(
          '* * * * *',
        ),
      ),
    ),
    'launcher' => array(
      'name' => 'serial',
      'serial' => array(
        'thread' => 'any',
      ),
    ),
    'logger' => array(
      'name' => 'cache',
      'cache' => array(
        'bin' => 'my_cache_bin',
      ),
    ),
  );
  return $items;
}