Example #1
0
 /**
  * Adds a worker to the action.
  *
  * @param Worker $worker
  *
  * @return Action
  * @throws \Exception
  */
 public function addWorker($worker)
 {
     if (!$worker instanceof Worker) {
         throw new \Exception('$worker is not an instance of Worker');
     }
     $this->workerList[$worker->getId()] = $worker;
     return $this;
 }
Example #2
0
 /**
  * Save or update worker
  * @param Worker $worker
  * @return Worker
  */
 public function saveWorker(Worker $worker)
 {
     if (is_null($worker->getId())) {
         $query = $this->db->prepare("INSERT INTO workers (host, port, type, status) VALUES (?, ?, ?, ?)");
         $query->execute([$worker->getHost(), $worker->getPort(), $worker->getType(), $worker->getStatus()]);
         $worker->setId($this->db->lastInsertId());
     } else {
         $query = $this->db->prepare("UPDATE workers SET host = ?, port = ?, type = ?, status = ? WHERE id = ?");
         $query->execute([$worker->getHost(), $worker->getPort(), $worker->getType(), $worker->getStatus(), $worker->getId()]);
     }
     return $worker;
 }
Example #3
0
 /**
  * Send task over RPC to worker
  * Mark task as in progress nad worker as busy
  * @param  Task   $task
  * @param  Worker $worker
  * @return void
  * @author Andraz <*****@*****.**>
  */
 public function sendTaskToWorker(Task $task, Worker $worker)
 {
     $client = $this->newRpcClient($worker->getHost(), $worker->getport());
     $parameters = [$worker->getId(), $task->getId(), $task->getParameters()];
     $task->setStatus('in_progress');
     $this->storage->saveTask($task);
     $worker->setStatus('busy');
     $this->storage->saveWorker($worker);
     $success = $client->notify('run', $parameters);
     if ($success) {
     }
     return $success;
 }