Esempio n. 1
0
<?php

/**
 * @author bigbigant
 */
require __DIR__ . '/bootstrap.inc.php';
Comos\Qpm\Log\Logger::useSimpleLogger(__FILE__ . '.log');
class Task implements Comos\Qpm\Process\Runnable
{
    public function __construct($taskId, $sleepTime)
    {
        $this->_taskId = $taskId;
        $this->_sleepTime = $sleepTime;
    }
    public function run()
    {
        $time = date("H:i:s");
        sleep($this->_sleepTime);
        file_put_contents(__FILE__ . '.log', sprintf("%s\t%d\t%d\n", $time, $this->_taskId, $this->_sleepTime), FILE_APPEND);
    }
}
class TaskFactory
{
    private $_plan = array(1, 1, 1, 3, 5, 5, null, 5, 6, 7, null, null, null, 8);
    private $_index = 0;
    private $_lastIsNull = false;
    public function fetchTask()
    {
        $task = $this->_doFetchTask();
        if ($task) {
            $this->_lastIsNull == false;
Esempio n. 2
0
<?php

/**
 * @author bigbigant
 */
require __DIR__ . '/bootstrap.inc.php';
$logFile = __FILE__ . '-simple-Logger.log';
Comos\Qpm\Log\Logger::useSimpleLogger($logFile);
echo "Execute 'tail {$logFile}' to see the lastest logs.\n";
$func = function () {
    $i = 3;
    while (--$i) {
        sleep(1);
    }
};
try {
    Comos\Qpm\Supervision\Supervisor::oneForOne(array('worker' => $func, 'quantity' => 3, 'maxRestartTimes' => 3))->start();
} catch (Exception $ex) {
    Comos\Qpm\Log\Logger::err($ex);
}