function next_sequence_number() { $next = 0; foreach (get_job_list() as $job) { if ($job->get_sequence_number() > $next) { $next = $job->get_sequence_number(); } } return $next + 1; }
<?php $base = dirname(__FILE__); $solr_root = substr($base, 0, strrpos($base, 'scripts')); $script_root = $solr_root . "/scripts"; include_once $script_root . "/common.php"; $to_run_jobs = array(); $job_list = get_job_list($link); //find to run jobs $current_time = time(); $date_time = date('Y-m-d H:i:s', $current_time); foreach ($job_list as $job) { if (!in_array($job['job_type'], $cfg['execute_cron'])) { continue; } $last_run_time = strtotime($job['last_run_time']); if ($job['plan_run_interval']) { if ($current_time - $last_run_time >= $job['plan_run_interval'] * 60) { $to_run_jobs[] = $job['job_script']; upd_job_run_time($link, $job['job_id'], $date_time); } } elseif ($job['plan_run_time']) { $current_hour = date('G', $current_time); $last_run_hour = date('G', $last_run_time); $plan_run_time = explode(',', $job['plan_run_time']); if (in_array($current_hour, $plan_run_time) && $current_hour != $last_run_hour) { $to_run_jobs[] = $job['job_script']; upd_job_run_time($link, $job['job_id'], $date_time); } } }
public function processAPI() { switch ($this->method) { case "GET": $gotNew = false; // get older jobs first $allJobs = get_job_list(); sort($allJobs); foreach ($allJobs as $job) { // found a new job if ($job->is_new()) { $JSON = array('newJob' => true, 'jobID' => $job->id, 'dependencies' => $job->get_dependency_links()); $gotNew = true; // log $GLOBALS['log']->info('Found new job with ID: ' . $job->id); break; } } // if no new jobs if (!$gotNew) { $JSON = array('newJob' => false); // log //$GLOBALS['log']->info('No new job found!'); } // send JSON $this->response($JSON); break; case "PUT": if (!isset($this->args[0])) { $GLOBALS['log']->error('Queue ID not set!'); $this->fail("Invalid queue ID", 406); } // check type is json if ($_SERVER['CONTENT_TYPE'] != "application/json") { $GLOBALS['log']->error('Unsupported content type: ' . $_SERVER['CONTENT_TYPE']); $this->fail("Unsupported content type. Expecting: application/json.", 500); } // if job with this id does not exist, fail $jobID = $this->args[0]; if (!job_exists($jobID)) { $GLOBALS['log']->error('No job with ID ' . $jobID); $this->fail("Invalid queue ID, no such job", 406); } $job = new Job($jobID); // parse incoming json $json = file_get_contents('php://input'); $json = json_decode($json, true); if ($json == null) { $GLOBALS['log']->error('Incorrectly formatted json input.'); $this->fail("Incorrectly formatted json input.", 500); } // update job if ($json['action'] == 'update') { // status update if (isset($json['status'])) { if ($json['status'] == 'submitted') { $job->set_to_submitted(); $GLOBALS['log']->info('Job ' . $jobID . ' status set to SUBMITTED.'); } elseif ($json['status'] == 'running') { // since we update the status with all messages, log just the first time if (!$job->is_running()) { $GLOBALS['log']->info('Job ' . $jobID . ' status set to RUNNING.'); } $job->set_to_running(); } elseif ($json['status'] == 'success') { $job->set_to_success(); $GLOBALS['log']->info('Job ' . $jobID . ' status set to SUCCESS.'); } elseif ($json['status'] == 'fail') { $job->set_to_fail(); $GLOBALS['log']->info('Job ' . $jobID . ' status set to FAIL.'); } } // tracking URL if (isset($json['tracking'])) { // since we update the url with all messages, log just the first time if (!$job->has_hadoop_track_link()) { $GLOBALS['log']->info('Job ' . $jobID . ' setting tracking link.'); } $job->set_hadoop_track_link($json['tracking']); } // progress if (isset($json['progress'])) { $job->update_progress($json['progress']); //$GLOBALS['log']->info('Job '.$jobID. ' updating progress.'); } // hadoop out if (isset($json['hadoop_out'])) { $job->store_hadoop_out($json['hadoop_out']); $GLOBALS['log']->info('Job ' . $jobID . ' storing hadoop out.'); } } break; default: $GLOBALS['log']->error('Method not allowed!.'); $this->fail("Method not allowed.", 405); } }
<tr> <th class="text-center">#</th> <th class="text-center">Date</th> <th class="text-center">Time</th> <th class="text-center">Progress</th> <th class="text-center">Hadoop Tracking</th> <th class="text-center">Search Results</th> <th class="text-center">Hadoop Out</th> <th class="text-center">Filled Form</th> </tr> </thead> <tbody> <?php // fill results from files $allJobs = get_job_list(); // if page > last page set it to last page $numPages = ceil(sizeof($allJobs) / $PER_PAGE); if ($PAGE > $numPages) { $PAGE = $numPages; } // get the slice for this page $jobs = array_slice($allJobs, ($PAGE - 1) * $PER_PAGE, $PER_PAGE); // for each job foreach ($jobs as $job) { $class = ''; $status = ''; if ($job->is_new()) { $class = 'warning'; $status = 'QUEUED'; } elseif ($job->is_submitted()) {