You are here

function drush_ultimate_cron_cron_unlock in Ultimate Cron 7.2

Same name and namespace in other branches
  1. 8.2 ultimate_cron.drush.inc \drush_ultimate_cron_cron_unlock()
  2. 8 ultimate_cron.drush.inc \drush_ultimate_cron_cron_unlock()
  3. 6 ultimate_cron.drush.inc \drush_ultimate_cron_cron_unlock()
  4. 7 ultimate_cron.drush.inc \drush_ultimate_cron_cron_unlock()

Unlock a cron job.

File

./ultimate_cron.drush.inc, line 488
Drush commands for Ultimate Cron!

Code

function drush_ultimate_cron_cron_unlock($name = NULL) {
  if (!$name) {
    if (!drush_get_option('all')) {
      return drush_set_error(dt('No job specified?'));
    }
    foreach (_ultimate_cron_job_load_all() as $job) {
      if ($job
        ->isLocked()) {
        drush_ultimate_cron_cron_unlock($job->name);
      }
    }
    return;
  }
  $job = _ultimate_cron_job_load($name);
  if (!$job) {
    return drush_set_error(dt('@name not found', array(
      '@name' => $name,
    )));
  }
  $lock_id = $job
    ->isLocked();
  if (!$lock_id) {
    return drush_set_error(dt('@name is not running', array(
      '@name' => $name,
    )));
  }

  // Unlock the process.
  if ($job
    ->unlock($lock_id, TRUE)) {
    $log_entry = $job
      ->resumeLog($lock_id);
    global $user;
    watchdog('ultimate_cron', '@name manually unlocked by user @username (@uid)', array(
      '@name' => $job->name,
      '@username' => $user->name,
      '@uid' => $user->uid,
    ), WATCHDOG_NOTICE);
    $log_entry
      ->finish();
    drush_print(dt('Cron job @name unlocked', array(
      '@name' => $name,
    )));
  }
  else {
    drush_set_error(dt('Could not unlock cron job @name', array(
      '@name' => $name,
    )));
  }
}