$startTime = new DateTime('now'); //We run every minute if ($startTime->format('i') == $previous->format('i')) { //Sleep interval, first sleep will be long sleep(isset($sleep) ? 1 : 60 - $startTime->format('i')); unset($startTime); //Next sleeps will be shorter $sleep = true; continue; } //Update previous start time with current unset($previous); $previous = $startTime; try { //Initializes task factory $launcher = new Launcher($startTime); //Performs health check at each start Launcher::healthcheck(); $launcher->setLogger($logger)->launch(); } catch (ZMQException $e) { if ($e->getCode() == 4) { //Catches ETERM $interrupt++; usleep(1); break; } $logger->fatal("Launcher error: %s", $e->getMessage()); } //Release resources unset($launcher); unset($startTime);
/** * {@inheritdoc} * @see \Scalr\System\Zmq\Cron\TaskInterface::addWorker() */ public function addWorker($address = null) { $op = []; $config = $this->config(); $args = '--name=' . ($address ?: $this->name); exec(Launcher::getStartWorkerCommand() . ' ' . $args . ' ' . ($config->log == '/dev/null' ? '>' : '>>') . ' ' . escapeshellcmd($config->log) . ' 2>&1 & echo $!', $op); $this->getLogger()->debug("Adding %s worker PID:%d", $address ?: $this->name, intval($op[0])); return intval($op[0]); }