function tripal_add_job

2.x tripal_core.jobs.api.inc tripal_add_job($job_name, $modulename, $callback, $arguments, $uid, $priority = 10)
3.x tripal.jobs.api.inc tripal_add_job($job_name, $modulename, $callback, $arguments, $uid, $priority = 10, $includes = array(), $ignore_duplicate = FALSE)
1.x tripal_core_jobs.api.inc tripal_add_job($job_name, $modulename, $callback, $arguments, $uid, $priority = 10)

Adds a job to the Tripal Job 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);

  $includes = array()
  $includes[] = module_load_include('inc', 'tripal_chado', 
                               'includes/loaders/tripal_chado.fasta_loader');

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

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.

$includes: An array of paths to files that should be included in order to execute the job. Use the module_load_include function to get a path for a given file.

$ignore_duplicate.: Set to TRUE to not add the job if it has the same name as another job which has not yet run. The default is TRUE.

Return value

The job_id of the registered job, or FALSE on failure.

Example usage:

Related topics

26 calls to tripal_add_job()
chado_add_admin_form_set_url_form_submit in legacy/tripal_core/api/tripal_core.chado_nodes.title_and_path.inc
Implements hook_form_submit(). SUBMIT: Actually add the format specified by chado_add_admin_form_set_title()
chado_insert_phylotree in tripal_chado/api/modules/tripal_chado.phylotree.api.inc
Inserts a phylotree record into Chado.
chado_node_sync_form_submit in legacy/tripal_core/api/tripal_core.chado_nodes.api.inc
Generic Sync Form Submit
chado_refresh_mview in tripal_chado/api/tripal_chado.mviews.api.inc
Populates the specified Materialized View.
chado_submit_obo_job in tripal_chado/api/modules/tripal_chado.cv.api.inc
TODO: deprecate this function

... See full list

File

tripal/api/tripal.jobs.api.inc, line 78
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, $includes = array(), $ignore_duplicate = FALSE) {

  $user = user_load($uid);

  try {
    $job = new TripalJob();
    $is_created = $job->create(array(
      'job_name' => $job_name,
      'modulename' => $modulename,
      'callback' => $callback,
      'arguments' => $arguments,
      'uid' => $uid,
      'priority' => $priority,
      'includes' => $includes,
      'ignore_duplicate' => $ignore_duplicate,
    ));

    if ($is_created) {
      // If no exceptions were thrown then we know the creation worked.  So
      // let the user know!
      drupal_set_message(t("Job '%job_name' submitted.", array('%job_name' => $job_name)));

      // If this is the Tripal admin user then give a bit more information
      // about how to run the job.
      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("Job '%job_name' already exists in the queue and was not re-submitted.", array('%job_name' => $job_name)), 'warning');
    }
    return $job->getJobID();
  }
  catch (Exception $e) {
    tripal_report_error('tripal', TRIPAL_ERROR, $e->getMessage());
    drupal_set_message($e->getMessage(), 'error');
    return FALSE;
  }
}