Esempio n. 1
0
 /**
  * The start action, it shows the "search" view
  */
 public function indexAction()
 {
     $searchParams = ['ping.batchId' => 'batchId', 'ping.proxyId' => 'proxyId', 'b.urlId' => 'urlId'];
     Tag::setDefaults(array('urlId' => $this->request->get('urlId'), 'proxyId' => $this->request->get('proxyId'), 'pingId' => $this->request->get('pingId'), 'batchId' => $this->request->get('batchId')));
     $this->view->pings = $this->searchPings($searchParams);
     $this->view->proxies = Proxy::find();
     $this->view->urls = Url::find();
     $this->view->batches = Batch::find();
     #$this->view->disable();
 }
Esempio n. 2
0
 /**
  * The start action, it shows the "search" view
  */
 public function indexAction()
 {
     $batchId = $this->request->get('batchId');
     $name = $this->request->get('name');
     $httpCode = $this->request->get('httpCode');
     if (!is_numeric($httpCode)) {
         $httpCode = '';
     }
     if (is_numeric($batchId)) {
         $batch = Batch::findFirst($batchId);
         if (!empty($batch)) {
             $batch->name = $name ?: $batch->name;
         }
     } else {
         $batch = new Batch();
     }
     Tag::setDefaults(array('batchId' => $batchId, 'name' => $name, 'httpCode' => $httpCode));
     $this->view->batch = $batch;
     $this->view->batchIds = Batch::find();
     $this->view->pings = $this->searchPings();
     #$this->view->disable();
 }
Esempio n. 3
0
 /**
  * Every time you click a tab or the 'next' button, this function fires. 
  * It combines the Input fields with the JobConfiguration that we already have in the Session.
  */
 public function postFormPart($next)
 {
     if (Input::has('batch')) {
         // TODO: Validate for CSRF
         $batch = Batch::find(Input::get('batch'));
         // TODO -- is saving batch in the session a good idea ?
         Session::put('batch', serialize($batch));
     } else {
         $batch = unserialize(Session::get('batch'));
         if (empty($batch)) {
             Session::flash('flashNotice', 'Please select a batch first.');
             return Redirect::to("jobs2/batch");
         }
     }
     return Redirect::to("jobs2/submit");
 }
Esempio n. 4
0
 public function d011($id = null)
 {
     if (!is_null($id)) {
         $result = Batch::find($id);
         $result->delete();
         ZiUtil::to_json(json_encode("{ success: true}"));
         return;
     }
     App::flash('error', 'Terjadi kesalahan pada inputan anda.');
     App::redirect('batch.index');
 }
Esempio n. 5
0
 public function postFormPart($next)
 {
     $jc = unserialize(Session::get('jobconf', serialize(new JobConfiguration())));
     if (isset($jc->content)) {
         $jcc = $jc->content;
     } else {
         $jcc = array();
     }
     $template = Session::get('template');
     if (Input::has('batch')) {
         // TODO: CSRF
         $batch = Batch::find(Input::get('batch'));
         Session::put('batch', serialize($batch));
     } else {
         $batch = unserialize(Session::get('batch'));
         if (empty($batch)) {
             Session::flash('flashNotice', 'Please select a batch first.');
             return Redirect::to("jobs/batch");
         }
     }
     if (Input::has('template')) {
         // Create the JobConfiguration object if it doesn't already exist.
         $ntemplate = Input::get('template');
         if (empty($template) or $template != $ntemplate) {
             $jc = JobConfiguration::fromJSON(Config::get('config.templatedir') . "{$ntemplate}.json");
         }
         $template = $ntemplate;
         $origjobconf = 'jcid';
         // TODO!
         // FOR TESTING -> static questiontemplate. // TODO!
         $filename = Config::get('config.templatedir') . $template . '.questiontemplate.json';
         if (file_exists($filename)) {
             $testdata = json_decode(file_get_contents($filename), true);
         } else {
             $testdata = null;
         }
         /*if($testdata == null) 
         		Session::flash('flashNotice', 'JSON not found or incorrectly formatted.');*/
         $qt = new QuestionTemplate();
         $qt->format = $batch->format;
         $qt->domain = $batch->domain;
         $qt->content = $testdata;
         $hash = md5(serialize($qt->content));
         $existing = QuestionTemplate::where('hash', $hash)->pluck('_id');
         if ($existing) {
             $qtid = $existing;
         } else {
             $qt->hash = $hash;
             $qt->save();
             $qtid = $qt->_id;
         }
         Session::put('questiontemplateid', $qtid);
         //////////////////////////////////////////////////////////
     } else {
         if (empty($jc)) {
             // No JobConfiguration and no template selected, not good.
             if ($next != 'template') {
                 Session::flash('flashNotice', 'Please select a template first.');
             }
             return Redirect::to("jobs/template");
         } else {
             // There already is a JobConfiguration object. Merge it with Input!
             $jcc = array_merge($jcc, Input::get());
             // If leaving the details page...
             if (Input::has('title')) {
                 $jcc['answerfields'] = Input::get('answerfields', false);
                 if ($next == 'nextplatform') {
                     if (isset($jcc['platform'][0])) {
                         $next = $jcc['platform'][0];
                     } else {
                         Session::flash('flashNotice', 'Please select a platform first');
                         return Redirect::to("jobs/platform");
                     }
                 }
             }
             // If leaving the Platform page....:
             if (Input::has('platformpage')) {
                 $jcc['platform'] = Input::get('platform', array());
             }
             // DEFAULT VALUES
             if (!isset($jcc['eventType'])) {
                 $jcc['eventType'] = 'HITReviewable';
             }
             if (!isset($jcc['frameheight'])) {
                 $jcc['frameheight'] = 650;
             }
             unset($jcc['_token']);
             $jc->content = $jcc;
             // After specific platform tab, call the method and determine which is next.
             $pid = Input::get('platformid', false);
             if ($pid) {
                 $platform = App::make($pid);
                 $jc = $platform->updateJobConf($jc);
                 if ($next == 'nextplatform') {
                     $nextindex = array_search($pid, $jc->content['platform']) + 1;
                     if (array_key_exists($nextindex, $jc->content['platform'])) {
                         $next = $jc->content['platform'][$nextindex];
                     } else {
                         $next = 'submit';
                     }
                 }
             }
         }
     }
     Session::put('jobconf', serialize($jc));
     Session::put('template', $template);
     try {
         return Redirect::to("jobs/{$next}");
     } catch (Exception $e) {
         Session::flash('flashError', $e->getMessage());
         // Todo: is this a good way? -> logging out due to timeout
         return Redirect::to("jobs");
     }
 }
Esempio n. 6
0
 /**
  * Message Queue Listener + Process task
  * @param job   $job            Laravel job object
  * @param object    $message    message detail (contains task id)
  */
 public function fire($job, $message)
 {
     $id = intval($message['id']);
     $batch = Batch::find($id);
     if ($batch->cancel) {
         $job->delete();
         $batch->setStatus('canceled');
         return;
     }
     $batch->setStatus('running');
     $batch->stampBeginExecDatetime();
     $rscriptCommand = Config::get('r.rscript');
     $rAppPath = base_path() . "/rscripts/app.R batch_controller.R";
     $execCommand = $rscriptCommand . " " . $rAppPath . " " . $id;
     $process = new Process($execCommand);
     $process->start();
     while ($process->isRunning()) {
         usleep(200000);
         if (Batch::isCanceled($id)) {
             // Kill Process
             $process->stop(3, SIGINT);
             $batch->setStatus('canceled');
             $batch->stampFinishDatetime();
             $job->delete();
             return;
         }
     }
     $output = $process->getOutput();
     # get new status after exec R file
     $batch = Batch::find($id);
     $batch->stampFinishDatetime();
     # write to logfile
     $logfile = fopen(base_path() . '/public/batchreport/' . $batch->id . ".log", "w+");
     fwrite($logfile, $output);
     fclose($logfile);
     # Check if task if finish running
     if ($batch->status != "success") {
         $batch->setStatus('fail');
     }
     try {
         $job->delete();
     } catch (\Exception $e) {
     }
 }