function tripal_is_job_running

2.x tripal_core.jobs.api.inc tripal_is_job_running()

Indicates if any jobs are running.

This function will check the system to see if a job has a process ID and if that process ID is still running. It will update the job status accordingly before returning.

Return value

Returns TRUE if any job is running or FALSE otherwise.

Related topics

3 calls to tripal_is_job_running()
tripal_jobs_check_running in tripal_core/api/tripal_core.DEPRECATED.api.inc
tripal_jobs_report in tripal_core/includes/tripal_core.jobs.inc
Returns the Tripal Job Report
tripal_launch_job in tripal_core/api/tripal_core.jobs.api.inc
A function used to manually launch all queued tripal jobs
1 string reference to 'tripal_is_job_running'

File

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

Code

function tripal_is_job_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);
  foreach ($jobs as $job) {
    $status = shell_exec('ps -p ' . escapeshellarg($job->pid) . ' -o 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;
}