Beispiel #1
0
 public function process()
 {
     $request = $this->node->request();
     if (!$request) {
         return true;
     }
     $requestKey = $request['key'];
     // Check the result data in the storage
     $data = $this->node->checkData($requestKey);
     if ($data) {
         $this->node->notify(json_encode(['data_key' => $requestKey, 'request_key' => $requestKey]));
         $this->logger->info('Result data found, notification sent', ['request_key' => $requestKey]);
         return true;
     }
     $request['key'] = $requestKey;
     $workload = json_encode($request);
     if (!$this->node->checkIndex($requestKey)) {
         $this->node->addToIndex($requestKey);
         $this->addTaskBackground($this->function, $workload);
         $this->logger->info('Task added', ['request_key' => $requestKey]);
     } else {
         $this->logger->info('Trying to add duplicate task', ['request_key' => $requestKey]);
     }
     return parent::process();
 }
Beispiel #2
0
 /**
  * Method for handle data saving logic. Can be redefined in child classes.
  */
 protected function saveResults()
 {
     $this->node->saveData($this->workload['key'], ['data' => $this->results]);
 }
Beispiel #3
0
 /**
  * Method for prepare request to parent node or doing another actions. Can be redefined in child classes,
  * but must return string with unique key of request. By default return the result of \Pipeline::sendRequest() call, and it is good practice.
  * In this method defines which commands will requested for parent node. By default client request just resend.
  * @param array $request Client request
  * @return string
  */
 protected function prepareRequest(array $request)
 {
     $this->logger->debug('Prepare request to parent node', ['key' => md5($request['key'])]);
     return $this->node->sendRequest(json_encode($request));
 }