Tripal v1.0 (6.x-1.0)
jobs.php
Go to the documentation of this file.
00001 <?php
00002 
00013 function tripal_jobs_report_form($form, &$form_state = NULL) {
00014   $form = array();
00015 
00016   // set the default values
00017   $default_status = $form_state['values']['job_status'];
00018 
00019   if (!$default_status) {
00020     $default_status = $_SESSION['tripal_job_status_filter'];
00021   }
00022 
00023   $form['job_status'] = array(
00024     '#type'          => 'select',
00025     '#title'         => t('Filter by Job Status'),
00026     '#default_value' => $default_status,
00027     '#options' => array(
00028             0           => 'All Jobs',
00029             'Running'   => 'Running',
00030             'Waiting'   => 'Waiting',
00031             'Completed' => 'Completed',
00032             'Cancelled' => 'Cancelled',
00033             'Error'     => 'Error',
00034           ),
00035   );
00036 
00037   $form['submit'] = array(
00038     '#type'         => 'submit',
00039     '#value'        => t('Filter'),
00040   );
00041   return $form;
00042 }
00047 function tripal_jobs_report_form_submit($form, &$form_state = NULL) {
00048   $job_status = $form_state['values']['job_status'];
00049   $_SESSION['tripal_job_status_filter'] = $job_status;
00050 }
00059 function tripal_jobs_report() {
00060 
00061   // run the following function which will
00062   // change the status of jobs that have errored out
00063   tripal_jobs_check_running();
00064 
00065         $jobs_status_filter = $_SESSION['tripal_job_status_filter'];
00066 
00067   $sql = "
00068     SELECT
00069       TJ.job_id,TJ.uid,TJ.job_name,TJ.modulename,TJ.progress,
00070       TJ.status as job_status, TJ,submit_date,TJ.start_time,
00071       TJ.end_time,TJ.priority,U.name as username
00072     FROM {tripal_jobs} TJ
00073       INNER JOIN {users} U on TJ.uid = U.uid ";
00074   if ($jobs_status_filter) {
00075     $sql .= "WHERE TJ.status = '%s' ";
00076   }
00077   $sql .= "ORDER BY job_id DESC";
00078 
00079   $jobs = pager_query($sql, 25, 0, "SELECT count(*) FROM ($sql) as t1", $jobs_status_filter);
00080   $header = array(
00081     'Job ID',
00082     'User',
00083     'Job Name',
00084     array('data' => 'Dates', 'style'=> "white-space: nowrap"),
00085     'Priority',
00086     'Progress',
00087     'Status',
00088     'Action');
00089   $rows = array();
00090 
00091   // iterate through the jobs
00092   while ($job = db_fetch_object($jobs)) {
00093     $submit = tripal_jobs_get_submit_date($job);
00094     $start = tripal_jobs_get_start_time($job);
00095     $end = tripal_jobs_get_end_time($job);
00096     $cancel_link = '';
00097     if ($job->start_time == 0 and $job->end_time == 0) {
00098       $cancel_link = "<a href=\"" . url("admin/tripal/tripal_jobs/cancel/" . $job->job_id) . "\">Cancel</a><br />";
00099     }
00100     $rerun_link = "<a href=\"" . url("admin/tripal/tripal_jobs/rerun/" . $job->job_id) . "\">Re-run</a><br />";
00101     $view_link ="<a href=\"" . url("admin/tripal/tripal_jobs/view/" . $job->job_id) . "\">View</a>";
00102     $rows[] = array(
00103       $job->job_id,
00104       $job->username,
00105       $job->job_name,
00106       "Submit Date: $submit<br>Start Time: $start<br>End Time: $end",
00107       $job->priority,
00108       $job->progress . '%',
00109       $job->job_status,
00110       "$cancel_link $rerun_link $view_link",
00111     );
00112   }
00113 
00114   // create the report page
00115   $output .= "Waiting jobs are executed first by priority level (the lower the ".
00116              "number the higher the priority) and second by the order they ".
00117              "were entered";
00118   $output .= drupal_get_form('tripal_jobs_report_form');
00119   $output .= theme('table', $header, $rows);
00120   $output .= theme_pager();
00121   return $output;
00122 }
00133 function tripal_jobs_view($job_id) {
00134   return theme('tripal_core_job_view', $job_id);
00135 }
00136 
00145 function tripal_core_preprocess_tripal_core_job_view(&$variables) {
00146 
00147   // get the job record
00148   $job_id = $variables['job_id'];
00149   $sql =
00150     "SELECT TJ.job_id,TJ.uid,TJ.job_name,TJ.modulename,TJ.progress,
00151             TJ.status as job_status, TJ,submit_date,TJ.start_time,
00152             TJ.end_time,TJ.priority,U.name as username,TJ.arguments,
00153             TJ.callback,TJ.error_msg,TJ.pid
00154      FROM {tripal_jobs} TJ
00155        INNER JOIN users U on TJ.uid = U.uid
00156      WHERE TJ.job_id = %d";
00157   $job = db_fetch_object(db_query($sql, $job_id));
00158 
00159   // we do not know what the arguments are for and we want to provide a
00160   // meaningful description to the end-user. So we use a callback function
00161   // deinfed in the module that created the job to describe in an array
00162   // the arguments provided.  If the callback fails then just use the
00163   // arguments as they are
00164   $args = preg_split("/::/", $job->arguments);
00165   $arg_hook = $job->modulename . "_job_describe_args";
00166   if (is_callable($arg_hook)) {
00167     $new_args = call_user_func_array($arg_hook, array($job->callback, $args));
00168     if (is_array($new_args) and count($new_args)) {
00169       $job->arguments = $new_args;
00170     }
00171     else {
00172       $job->arguments = $args;
00173     }
00174   }
00175   else {
00176     $job->arguments = $args;
00177   }
00178 
00179   // make our start and end times more legible
00180   $job->submit_date = tripal_jobs_get_submit_date($job);
00181   $job->start_time = tripal_jobs_get_start_time($job);
00182   $job->end_time = tripal_jobs_get_end_time($job);
00183 
00184   // add the job to the variables that get exported to the template
00185   $variables['job'] = $job;
00186 }
00187 
00188 
 All Classes Files Functions Variables