Since: 5.0 (22.09.2014)
Author: Vitaliy Demidov (vitaliy@scalr.com)
Inheritance: use trait Scalr\LoggerAwareTrait
コード例 #1
0
ファイル: client.php プロジェクト: scalr/scalr
}
//Service name is expected
$service = $opt['name'];
//name of the class in camel case
$cls = Scalr::camelize($service);
$logger = Scalr::getContainer()->logger('cron/client.php')->setLevel(Scalr::config('scalr.crontab.log_level'));
//Checking if task class exists.
if (!file_exists(SRCPATH . '/Scalr/System/Zmq/Cron/Task/' . $cls . '.php')) {
    $logger->fatal("Launch error. File %s does not exist.", SRCPATH . '/Scalr/System/Zmq/Cron/Task/' . $cls . '.php');
    exit;
}
$taskClass = 'Scalr\\System\\Zmq\\Cron\\Task\\' . $cls;
/* @var $task \Scalr\System\Zmq\Cron\AbstractTask */
$task = new $taskClass();
$taskConfig = $task->config();
$oPid = new PidFile(CACHEPATH . '/cron.client.' . $task->getName() . '.pid', '/client.php');
$oPid->setLogger($logger);
$oPid->create();
$interrupt = 0;
//Signal handler callback function
$sigHandler = function ($signo = null) use(&$interrupt, $oPid, $task, $taskConfig) {
    static $once = 0;
    $interrupt++;
    if ($once++) {
        return;
    }
    $task->log($taskConfig->daemon ? 'SERVICE' : 'DEBUG', "Client recieved termination SIGNAL:%d", intval($signo));
    //Terminating child processes (workers)
    $task->shutdown();
    //Removing pid file
    $oPid->remove();