I am using Ultimate Cron for running individual cron runs and I see Ultimate Cron provide hook_cronapi() to create own cron task runs and provide enabled key as either TRUE or FALSE.

My objective is create two cron task one cron will run at specified time say 01:00pm and will update the enabled statues of second cron to TRUE so that it will run until it achieved certain condition during each 1 min interval of this second cron task and after this condition is met, will be shut down the second cron task status by setting disabled status to FALSE so that it stop processing uselessly.

So, how do I set that enabled status to TRUE/FALSE during its run time.

1 Answer 1


Answering my own question.

In your .info file first define ultimate_cron as dependencies

dependencies[] = ultimate_cron

Next, in your .module use hook_cronapi() and define two cron attributes.

 * Implements hook_cronapi().
function mymodule_cronapi() {
  $items = array();
  // This launches at specified time once a day.
  $items['custom_cron_1'] = array(
    'title' => t('This will run once every day'),
    'scheduler' => array(
      'name' => 'crontab',
      'crontab' => array(
        'rules' => array('* 2 * * *'),
  // Run only when invoked and until & unless condition is met so we are not left for tomorrow
  $items['custom_cron_2'] = array(
    'title' => t('Run when invoked'),
    'enabled' => FALSE,
    'scheduler' => array(
     'name' => 'crontab',
     'crontab' => array(
       'rules' => array('*/1 * * * *'),
  return $items;

Next step is to define the cron job callback and here in first callback we will schedule to run second cron job.

function custom_cron_1() {
  $job = _ultimate_cron_job_load('custom_cron_2');
  // Enable the job.

Next we will define callback for second cron and continue this cron process each minute until condition is met.

function custom_cron_2($job) {
  // Check for condition.
  if(...) {
  else {
    // Continue the process

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.