function tripal_jobs_launch

2.x tripal_core.DEPRECATED.api.inc tripal_jobs_launch($do_parallel = 0, $job_id = NULL)
3.x tripal_core.DEPRECATED.inc tripal_jobs_launch($do_parallel = 0, $job_id = NULL)
1.x tripal_core_jobs.api.inc tripal_jobs_launch($do_parallel = 0, $job_id = NULL)

A function used to manually launch all queued tripal jobs

Parameters

$do_parallel: A boolean indicating whether jobs should be attempted to run in parallel

$job_id: To launch a specific job provide the job id. This option should be used sparingly as the jobs queue managment system should launch jobs based on order and priority. However there are times when a specific job needs to be launched and this argument will allow it. Only jobs which have not been run previously will run.

Related topics

3 calls to tripal_jobs_launch()
drush_tripal_core_tripal_jobs_launch in tripal_core/tripal_core.drush.inc
Executes jobs in the Tripal Jobs Queue
runjob in tripal_core/tripal_launch_jobs_multi.php
Runs tripal_launch_jobs() as the specified user
tripal_launch_jobs.php in tripal_core/tripal_launch_jobs.php
This script will launch any waiting tripal jobs in succession.

File

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

Code

function tripal_jobs_launch($do_parallel = 0, $job_id = NULL) {

  // first check if any jobs are currently running
  // if they are, don't continue, we don't want to have
  // more than one job script running at a time
  if (!$do_parallel and tripal_jobs_check_running()) {
    print "Jobs are still running. Use the --parallel=1 option with the Drush command to run jobs in parallel.";
    return;
  }

  // get all jobs that have not started and order them such that
  // they are processed in a FIFO manner.
  if ($job_id) {
    $sql = "SELECT * FROM {tripal_jobs} TJ " .
      "WHERE TJ.start_time IS NULL and TJ.end_time IS NULL and TJ.job_id = %d " .
      "ORDER BY priority ASC,job_id ASC";
    $job_res = db_query($sql, $job_id);
  }
  else {
    $sql = "SELECT * FROM {tripal_jobs} TJ " .
      "WHERE TJ.start_time IS NULL and TJ.end_time IS NULL " .
      "ORDER BY priority ASC,job_id ASC";
    $job_res = db_query($sql);
  }
  while ($job = db_fetch_object($job_res)) {
    // set the start time for this job
    $record = new stdClass();
    $record->job_id = $job->job_id;
    $record->start_time = time();
    $record->status = 'Running';
    $record->pid = getmypid();
    drupal_write_record('tripal_jobs', $record, 'job_id');

    // call the function provided in the callback column.
    // Add the job_id as the last item in the list of arguments. All
    // callback functions should support this argument.
    $callback = $job->callback;
    $args = split("::", $job->arguments);
    $args[] = $job->job_id;
    print "Calling: $callback(" . implode(", ", $args) . ")\n";
    call_user_func_array($callback, $args);
    // set the end time for this job
    $record->end_time = time();
    $record->status = 'Completed';
    $record->progress = '100';
    drupal_write_record('tripal_jobs', $record, 'job_id');

    // send an email to the user advising that the job has finished
  }
}