예제 #1
0
 public function execute()
 {
     $loop = true;
     while ($loop) {
         // 1. Find record with server = null
         $request = new Request(['server' => ''], [Request::EXTRA_LIMIT => 1]);
         $this->runUseCaseWithNoOfRetriesOnFail('task|retrieve', $request, $this->getMaxRetries());
         $response = $this->getUseCaseResponse();
         $result = $response->getResult();
         // 2. If there are no unassigned servers then, return
         $resultCount = $response->getTotalResultCount();
         if (empty($resultCount) || !isset($result[0])) {
             $loop = false;
             continue;
         }
         // 3. Get the id
         $id = $result[0]->getId();
         // 4. Lock by id
         $lockId = AssignManager::ID_TYPE . '-' . $id;
         $this->createLock($lockId);
         $response = $this->getUseCaseResponse();
         // 5. If it could not lock, then exit
         if (in_array(23000, $response->getCodes()) || $response->getStatus() == Response::STATUS_FAIL) {
             continue;
         }
         // 6. If there is no other record, then create a new task record
         $this->updateTaskById($id, $this->info->getHostname(), Task::STATUS_ID_ASSIGNED);
         // 7. Delete the lock record
         $this->deleteLock($lockId);
     }
 }
예제 #2
0
 private function doJob()
 {
     date_default_timezone_set('UTC');
     $info = new Information();
     // Save process to db
     $info->setProcessId(getmypid());
     $info->setHostname(gethostname());
     $info->setExtra(self::ID_TYPE);
     $info->setProcessMaxRetryTimeBeforeContinue($this->processMaxRetryTimeBeforeContinue);
     $request = new Request(['id' => $info->getProcessId(), 'server' => $info->getHostname(), 'extra' => $info->getExtra(), 'creatingDateTime' => date('Y-m-d H:i:s')]);
     $this->runUseCaseWithNoOfRetriesOnFail('process|create', $request, $this->processMaxRetryTimeBeforeContinue);
     $assignTask = new AssignTask($info);
     $assignTask->execute();
     $this->runUseCaseWithNoOfRetriesOnFail('process|delete', $request, $this->processMaxRetryTimeBeforeContinue);
 }
예제 #3
0
 public function testActTask()
 {
     //$this->cleanAndPopulateDatabase();
     $myObject = new ActCallback();
     $info = new Information();
     // Save process to db
     $info->setProcessId(1234);
     $info->setHostname('anim.stage.lsex.dev');
     $info->setExtra(1);
     $info->setProcessMaxRetryTimeBeforeContinue(3);
     $request = new Request(['id' => $info->getProcessId(), 'server' => $info->getHostname(), 'extra' => $info->getExtra(), 'creatingDateTime' => date('Y-m-d H:i:s')]);
     $this->runUseCaseWithNoOfRetriesOnFail('process|create', $request, 3);
     $actTask = new ActTask($info, $myObject, 2);
     $actTask->execute();
     $this->runUseCaseWithNoOfRetriesOnFail('process|delete', $request, 3);
 }