function tripal_jobs_check_running

2.x tripal_core.DEPRECATED.api.inc tripal_jobs_check_running()
3.x tripal_core.DEPRECATED.inc tripal_jobs_check_running()
1.x tripal_core_jobs.api.inc tripal_jobs_check_running()

Returns a list of running tripal jobs

Return value

and array of objects where each object describes a running job or FALSE if no jobs are running

Related topics

2 calls to tripal_jobs_check_running()
tripal_jobs_launch in tripal_core/api/tripal_core_jobs.api.inc
A function used to manually launch all queued tripal jobs
tripal_jobs_report in tripal_core/includes/jobs.inc
Returns the Tripal Job Report

File

tripal_core/api/tripal_core_jobs.api.inc, line 98
Contains functions related to the Tripal Jobs API

Code

function tripal_jobs_check_running() {

  // iterate through each job that has not ended
  // and see if it is still running. If it is not
  // running but does not have an end_time then
  // set the end time and set the status to 'Error'
  $sql = "SELECT * FROM {tripal_jobs} TJ " .
    "WHERE TJ.end_time IS NULL and NOT TJ.start_time IS NULL ";
  $jobs = db_query($sql);
  while ($job = db_fetch_object($jobs)) {
    $status = $job->pid;
    if ($job->pid && $status) {
      // the job is still running so let it go
      // we return 1 to indicate that a job is running
      return TRUE;
    }
    else {
      // the job is not running so terminate it
      $record = new stdClass();
      $record->job_id = $job->job_id;
      $record->end_time = time();
      $record->status = 'Error';
      $record->error_msg = 'Job has terminated unexpectedly.';
      drupal_write_record('tripal_jobs', $record, 'job_id');
    }
  }

  // return 1 to indicate that no jobs are currently running.
  return FALSE;
}