function tripal_add_job

2.x tripal_core.jobs.api.inc tripal_add_job($job_name, $modulename, $callback, $arguments, $uid, $priority = 10)
1.x tripal_core_jobs.api.inc tripal_add_job($job_name, $modulename, $callback, $arguments, $uid, $priority = 10)

Adds a job to the Tripal Jbo queue

 $args = array($dfile, $organism_id, $type, $library_id, $re_name, $re_uname,
       $re_accession, $db_id, $rel_type, $re_subject, $parent_type, $method,
        $user->uid, $analysis_id, $match_type);

tripal_add_job("Import FASTA file: $dfile", 'tripal_feature',
  'tripal_feature_load_fasta', $args, $user->uid);

The code above is copied from the tripal_feature/fasta_loader.php file. The snipped first builds an array of arguments that will then be passed to the tripal_add_job function. The number of arguments provided in the $arguments variable should match the argument set for the callback function provided as the third argument.

Parameters

$job_name: The human readable name for the job

$modulename: The name of the module adding the job

$callback: The name of a function to be called when the job is executed

$arguments: An array of arguments to be passed on to the callback

$uid: The uid of the user adding the job

$priority: The priority at which to run the job where the highest priority is 10 and the lowest priority is 1. The default priority is 10.

Return value

The job_id of the registered job

Example usage:

Related topics

21 calls to tripal_add_job()
chado_add_admin_form_set_url_form_submit in tripal_core/api/tripal_core.chado_nodes.title_and_path.api.inc
Implements hook_form_submit(). SUBMIT: Actually add the format specified by chado_add_admin_form_set_title()
chado_node_sync_form_submit in tripal_core/api/tripal_core.chado_nodes.api.inc
Generic Sync Form Submit
drush_tripal_bulk_loader_tripal_loader_submit in tripal_bulk_loader/tripal_bulk_loader.drush.inc
Submit or Re-submit the given bulk loading job.
hook_chado_node_sync_form_submit in tripal_core/api/tripal_core.chado_nodes.api.inc
Bypass chado node api sync form submit.
tripal_analysis_delete_form_submit in tripal_analysis/includes/tripal_analysis.delete.inc
Submit for the delete features form

... See full list

File

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

Code

function tripal_add_job($job_name, $modulename, $callback, $arguments, $uid, $priority = 10) {
  if (!$job_name) {
    watchdog('tripal', "Must provide a \$job_name argument to the tripal_add_job() function.", 'error');
    return FALSE;
  }
  if (!$modulename) {
    watchdog('tripal', "Must provide a \$modulename argument to the tripal_add_job() function.", 'error');
    return FALSE;
  }
  if (!$callback) {
    watchdog('tripal', "Must provide a \$callback argument to the tripal_add_job() function.", 'error');
    return FALSE;
  }

  if (!function_exists($callback)) {
    watchdog('tripal', "Must provide a valid callback function to the tripal_add_job() function.", 'error');
    return FALSE;
  }
  if (!is_numeric($uid)) {
    watchdog('tripal', "Must provide a numeric \$uid argument to the tripal_add_job() function.", 'error');
    return FALSE;
  }
  if (!$priority or !is_numeric($priority) or $priority < 1 or $priority > 10) {
    watchdog('tripal', "Must provide a numeric \$priority argument between 1 and 10 to the tripal_add_job() function.", 'error');
    return FALSE;
  }
  if (!is_array($arguments)) {
    watchdog('tripal', "Must provide an array as the \$arguments argument to the tripal_add_job() function.", 'error');
    return FALSE;
  }

  $user = user_load($uid);

  // convert the arguments into a string for storage in the database
  $args = array();
  if (is_array($arguments)) {
    $args = serialize($arguments);
  }

  $job_id = db_insert('tripal_jobs')
    ->fields(array(
      'job_name' => $job_name,
      'modulename' => $modulename,
      'callback' => $callback,
      'status' => 'Waiting',
      'submit_date' => time(),
      'uid' => $uid,
      # The lower the number the higher the priority.
      'priority' => $priority,
      'arguments' => $args,
    ))
    ->execute();

  if ($job_id) {
    drupal_set_message(t("Job '%job_name' submitted.", array('%job_name' => $job_name)));
    if (user_access('administer tripal')) {
      $jobs_url = url("admin/tripal/tripal_jobs");
      drupal_set_message(t("Check the <a href='!jobs_url'>jobs page</a> for status.", 
      array('!jobs_url' => $jobs_url)));
      drupal_set_message(t("You can execute the job queue manually on the command line " .
        "using the following Drush command: <br>drush trp-run-jobs --username=%uname --root=%base_path", 
      array('%base_path' => DRUPAL_ROOT, '%uname' => $user->name)));
    }
  }
  else {
    drupal_set_message(t("Failed to add job: %job_name.", array('%job_name' => $job_name)), 'error');
  }

  return $job_id;
}