Task queue boilerplate.
Since: 5.0.1 (10.09.2014)
Author: Vitaliy Demidov (vitaliy@scalr.com)
Inheritance: implements Scalr\System\Zmq\Cron\TaskInterface, use trait Scalr\LoggerAwareTrait
Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  * @see \Scalr\System\Zmq\Cron\AbstractTask::config()
  */
 public function config()
 {
     $config = parent::config();
     if ($config->daemon) {
         //Report a warning to the log
         trigger_error(sprintf("Demonized mode is not allowed for '%s' task. Forcing normal mode.", $this->name), E_USER_WARNING);
         //Forces normal mode
         $config->daemon = false;
     }
     return $config;
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  * @see \Scalr\System\Zmq\Cron\AbstractTask::config()
  */
 public function config()
 {
     $config = parent::config();
     if ($config->daemon) {
         //Report a warning to log
         trigger_error(sprintf("Demonized mode is not allowed for '%s' job.", $this->name), E_USER_WARNING);
         //Forces normal mode
         $config->daemon = false;
     }
     if ($config->workers != 1) {
         //It cannot be performed through ZMQ MDP as execution time exceeds heartbeat
         trigger_error(sprintf("It is allowed only one worker for the '%s' job.", $this->name), E_USER_WARNING);
         $config->workers = 1;
     }
     return $config;
 }
Exemplo n.º 3
0
 /**
  * Constructor
  */
 public function __construct()
 {
     parent::__construct();
     $this->db = \Scalr::getDb();
 }
Exemplo n.º 4
0
 /**
  * {@inheritdoc}
  * @see \Scalr\System\Zmq\Cron\AbstractTask::launchWorkers()
  */
 protected function launchWorkers($address = null)
 {
     $config = $this->config();
     //It launches different pools of workers according to replication schema defined in the config
     foreach (array_merge(!empty($config->replicate['type']) ? $config->replicate['type'] : [], ['all']) as $type) {
         if (!empty($config->replicate['account'])) {
             foreach ($config->replicate['account'] as $acc) {
                 parent::launchWorkers($this->name . '.' . $type . '.' . $acc);
             }
         }
         parent::launchWorkers($this->name . '.' . $type . '.all');
     }
 }
Exemplo n.º 5
0
 /**
  * Constructor
  */
 public function __construct()
 {
     parent::__construct();
     $this->db = \Scalr::getDb();
     $this->serializer = new Scalr_Messaging_XmlSerializer();
     $this->jsonSerializer = new Scalr_Messaging_JsonSerializer();
 }