function tripal_cancel_job

2.x tripal_core.jobs.api.inc tripal_cancel_job($job_id, $redirect = TRUE)

Cancel a Tripal Job currently waiting in the job queue

Parameters

$job_id: The job_id of the job to be cancelled

Return value

FALSE if the an error occured or the job could not be canceled, TRUE otherwise.

Related topics

3 calls to tripal_cancel_job()
drush_tripal_bulk_loader_tripal_loader_cancel in tripal_bulk_loader/tripal_bulk_loader.drush.inc
Cancels the specified bulk loading job.
tripal_bulk_loader_add_loader_job_form_submit in tripal_bulk_loader/includes/tripal_bulk_loader.loader.inc
Add Loader Job Form (Submit)
tripal_jobs_cancel in tripal_core/api/tripal_core.DEPRECATED.api.inc
2 string references to 'tripal_cancel_job'
tripal_core_menu in tripal_core/tripal_core.module
Implements hook_menu(). Defines all menu items needed by Tripal Core
tripal_jobs_cancel in tripal_core/api/tripal_core.DEPRECATED.api.inc

File

tripal_core/api/tripal_core.jobs.api.inc, line 355
Tripal offers a job management subsystem for managing tasks that may require an extended period of time for completion.

Code

function tripal_cancel_job($job_id, $redirect = TRUE) {

  if (!$job_id or !is_numeric($job_id)) {
    watchdog('tripal', "Must provide a numeric \$job_id to the tripal_cancel_job() function.");
    return FALSE;
  }

  $sql = "SELECT * FROM {tripal_jobs} WHERE job_id = :job_id";
  $results = db_query($sql, array(':job_id' => $job_id));
  $job = $results->fetchObject();

  // set the end time for this job
  if ($job->start_time == 0) {
    $record = new stdClass();
    $record->job_id = $job->job_id;
    $record->end_time = time();
    $record->status = 'Cancelled';
    $record->progress = '0';
    drupal_write_record('tripal_jobs', $record, 'job_id');
    drupal_set_message(t("Job #%job_id cancelled", array('%job_id' => $job_id)));
  }
  else {
    drupal_set_message(t("Job %job_id cannot be cancelled. It is in progress or has finished.", array('%job_id' => $job_id)));
  }
  if ($redirect) {
    drupal_goto("admin/tripal/tripal_jobs");
  }
}