private function prepare_disks($disks)
 {
     $disks_aux = array();
     foreach ($disks as $disk) {
         if ($disk['from_task_id']) {
             if ($jobObj = EtvaAsynchronousJobPeer::retrieveByPK($disk['from_task_id'])) {
                 if ($res_str = $jobObj->getResult()) {
                     $result = json_decode($res_str, true);
                     if ($result && $result['success']) {
                         $disk['id'] = $result['insert_id'];
                         $disk['uuid'] = $result['uuid'];
                     }
                 }
             }
         }
         array_push($disks_aux, $disk);
     }
     return $disks_aux;
 }
Example #2
0
 public function dependsFinished()
 {
     $depends = $this->getDepends();
     if ($depends) {
         $depends_arr = explode(',', $depends);
         foreach ($depends_arr as $s_dJob) {
             $dJob = $s_dJob;
             if (preg_match("/\\w+\\((\\d+)\\)/", $s_dJob, $matches)) {
                 $dJob = $matches[1];
             }
             if ($oJob = EtvaAsynchronousJobPeer::retrieveByPK($dJob)) {
                 if (!$oJob->finished()) {
                     return false;
                 }
             }
         }
     }
     return true;
 }
Example #3
0
 public function executeGet(sfWebRequest $request)
 {
     $id = $request->getParameter('id');
     $result = array('success' => false, 'error' => 'unknown error', 'agent' => sfConfig::get('config_acronym'));
     if ($etva_asyncjob = EtvaAsynchronousJobPeer::retrieveByPk($id)) {
         // get task
         $asyncjob_arr = $etva_asyncjob->toArray();
         $result = array('success' => true, 'response' => "Ok", 'agent' => sfConfig::get('config_acronym'), 'asynchronousjob' => $asyncjob_arr);
     } else {
         // invalid id
         $result = array('success' => false, 'error' => 'Invalid asynchronous job!', 'agent' => sfConfig::get('config_acronym'));
     }
     return $this->returnResponse($result);
 }
Example #4
0
 private function launch_asyncJob_worker($arguments, $options)
 {
     if (count($this->workers) < $this->max_workers) {
         $cpid = pcntl_fork();
         if (0 === $cpid) {
             $this->log("[INFO] Worker - new with pid=" . getmypid());
             // dequeue task
             $aJob_id = $this->dequeue_task();
             if ($aJob_id) {
                 $sem_lock = $this->init_proctask_lock($aJob_id);
                 if ($this->acquire_proctask_lock($sem_lock)) {
                     // init database
                     $this->init_database($arguments, $options);
                     $aJob = EtvaAsynchronousJobPeer::retrieveByPK($aJob_id);
                     $this->log("[INFO] Worker - check status of request task id=" . $aJob->getId() . "   task=" . $aJob->getTasknamespace() . ":" . $aJob->getTaskname() . " pid=" . getmypid());
                     $res = $aJob->checkStatus($this->dispatcher);
                     if (isset($res['success']) && !$res['success']) {
                         $this->log("[ERROR] Worker - Error execute task id=" . $aJob->getId() . " pid=" . getmypid() . " " . $res['error']);
                     } else {
                         //$this->log("[INFO] Worker - Task with id=".$aJob->getId()." pid=".getmypid(). " ... finished");
                     }
                     // close database
                     $this->close_database($arguments, $options);
                     $this->release_proctask_lock($sem_lock);
                     // release lock
                 }
             }
             exit(0);
         } else {
             array_push($this->workers, $cpid);
         }
     }
 }