Ejemplo n.º 1
0
 /**
  * Listen to new workers and add them to queue
  * @param  string $host
  * @param  string $port
  * @param  string $type
  * @return int
  * @author Andraz <*****@*****.**>
  */
 public function listen($host, $port, $type)
 {
     if ($worker = $this->storage->getWorkerByHost($host)) {
         return $worker->getId();
     }
     // save new worker
     $worker = new Worker();
     $worker->setHost($host);
     $worker->setPort($port);
     $worker->setType($type);
     $worker = $this->storage->saveWorker($worker);
     return $worker->getId();
 }
Ejemplo n.º 2
0
 /**
  * Get worker by id
  * @param int $id
  * @return Worker null
  */
 public function getWorker($id)
 {
     $result = $this->db->query("SELECT * FROM workers WHERE id = {$id}");
     foreach ($result as $key => $row) {
         $worker = new Worker();
         $worker->setId($row['id']);
         $worker->setHost($row['host']);
         $worker->setPort($row['port']);
         $worker->setType($row['type']);
         $worker->setStatus($row['status']);
         return $worker;
     }
     return null;
 }