create() public method

It performs pid file check itself
public create ( )
Ejemplo n.º 1
0
$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();
    //No use to proceed
    exit;