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, |
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 arguements 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
- 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.
- tripal_analysis_admin_validate in tripal_analysis/
includes/ tripal_analysis.admin.inc - Validate the administrative form @todo Stephen: Why is validate used rather then submit?
- tripal_bulk_loader_add_loader_job_form_submit in tripal_bulk_loader/
includes/ tripal_bulk_loader.loader.inc - Add Loader Job Form (Submit)
- tripal_bulk_loader_update in tripal_bulk_loader/
tripal_bulk_loader.module - Implements node_update Updates the data submitted by the node form on edit
- tripal_contact_admin_validate in tripal_contact/
includes/ tripal_contact.admin.inc
File
- tripal_core/
api/ tripal_core_jobs.api.inc, line 64 - Contains functions related to the Tripal Jobs API
Code
function tripal_add_job($job_name, $modulename, $callback, $arguments, $uid, $priority = 10) {
// convert the arguments into a string for storage in the database
$args = implode("::", $arguments);
$record = new stdClass();
$record->job_name = $job_name;
$record->modulename = $modulename;
$record->callback = $callback;
$record->status = 'Waiting';
$record->submit_date = time();
$record->uid = $uid;
$record->priority = $priority; # the lower the number the higher the priority
if ($args) {
$record->arguments = $args;
}
if (drupal_write_record('tripal_jobs', $record)) {
$jobs_url = url("admin/tripal/tripal_jobs");
drupal_set_message(t("Job '%job_name' submitted. Check the <a href='!jobs_url'>jobs page</a> for status", array('%job_name' => $job_name, '!jobs_url' => $jobs_url)));
}
else {
drupal_set_message(t("Failed to add job %job_name.", array('%job_name' => $job_name)), 'error');
}
return $record->job_id;
}