Пример #1
0
 public static function staticMethodWhichLogsOneRow(array $options = [])
 {
     $container = (include './config/container.php');
     $log = $container->get('tick_log_datastore');
     $itemData = ['tick_id' => UTCTime::getUTCTimestamp(), 'step' => preg_replace("/\\s+/", " ", var_export($options, 1))];
     $log->create($itemData);
 }
Пример #2
0
 public function test_deleteTask()
 {
     $this->_initTask();
     $this->assertEquals('ky', $this->task->activate(UTCTime::getUTCTimestamp(0), 1));
     $this->broker->deleteTask($this->task->getId());
     $this->assertNull($this->task->activate(UTCTime::getUTCTimestamp(0), 1));
 }
Пример #3
0
 /**
  * @param null $from
  */
 protected function setFrom($from = null)
 {
     // By default sets CURRENT_TIMESTAMP
     if (is_null($from)) {
         $from = UTCTime::getUTCTimestamp(0);
     }
     $this->from = $from;
 }
Пример #4
0
 /**
  * Checks a status of processes.
  *
  * If the process finished, reads its log files and return the status of finishing and errors/output
  */
 public function checkProcess()
 {
     // TODO: проверить все процессы. Зависшие закрыть принудительно (reject), остальные обработать
     $sortNode = new SortNode(['startedAt' => +1]);
     $query = new Query();
     $query->setSort($sortNode);
     $rows = $this->pidDataStore->query($query);
     foreach ($rows as $row) {
         $pId = intval($row['pId']);
         // checks timeout
         $expireTime = floatval($row['startedAt']) + intval($row['timeout']);
         if ($expireTime <= UTCTime::getUTCTimestamp()) {
             $this->killProcess($pId);
         }
         // checks process existing
         if (!posix_kill($pId, 0)) {
             // The process is finished
             $this->postFinishProcess($row);
             $this->pidDataStore->delete($row['id']);
         }
     }
 }
Пример #5
0
 /**
  * {@inherit}
  *
  * {@inherit}
  */
 public function call(array $options = [])
 {
     $cmd = "php " . $this->script;
     $cmd .= Script::makeParamsString(['scriptOptions' => Script::encodeParams($options)]);
     $cmd .= "  > /dev/null 2>&1 & echo \$!";
     $output = trim(shell_exec($cmd));
     if (!is_numeric($output)) {
         throw new CallbackException("The output of the script is ambiguous. Probably there is an error in the script");
     }
     $pId = intval($output);
     $itemData = ['pid' => $pId, 'startedAt' => UTCTime::getUTCTimestamp(), 'scriptName' => "Worker: ", 'timeout' => 30];
     $this->dataStore->create($itemData);
     return $pId;
 }
Пример #6
0
<?php

chdir(getcwd());
require './vendor/autoload.php';
use zaboy\scheduler\FileSystem\CommandLineWorker;
use zaboy\scheduler\DataStore\UTCTime;
$commandLineWorker = new CommandLineWorker();
$options = $commandLineWorker->getCallOptions($_SERVER['argv']);
$serviceName = 'tick_log_datastore';
/** @var Zend\ServiceManager\ServiceManager $container */
$container = (include './config/container.php');
if (!$container->has($serviceName)) {
    throw new Exception("The service \"{$serviceName}\" must be specified in config/datastore");
}
$log = $container->get('tick_log_datastore');
$itemData = ['tick_id' => UTCTime::getUTCTimestamp(), 'step' => print_r($options, 1)];
$log->create($itemData);
Пример #7
0
 /**
  * Checks if this hop works greater than "total_time + (total_time * overhead_time) / 100"
  *
  * @throws \Exception
  */
 protected function checkOverheadTime()
 {
     $now = UTCTime::getUTCTimestamp($this->step < 1);
     $passedTime = $now - $this->hopStart;
     $totalAllowedTime = $this->total_time * $this->critical_overtime / 100 + $this->total_time;
     if ($passedTime >= $totalAllowedTime) {
         throw new \Exception("Current hop already works greater than allowed overhead time.");
     }
 }
Пример #8
0
 public function test_compareTimelinesWithQuery()
 {
     $from = UTCTime::getUTCTimestamp(0);
     $timeline = [];
     // step is 3 seconds
     $rql = "and(or(eq(seconds,";
     for ($i = 0; $i < 15; $i += 3) {
         $dateInfo = $this->object->read($from + $i);
         $timeline[] = $dateInfo;
         $rql .= $dateInfo['seconds'];
         $rql .= "),eq(seconds,";
     }
     $rql = rtrim($rql, "),eq(seconds,") . ")),ge(timestamp," . $from . "))&limit(5,0)";
     $rqlQueryObject = $this->rqlParser->rqlDecoder($rql);
     $timelineDsRows = $this->object->query($rqlQueryObject);
     $this->assertEquals($timeline, $timelineDsRows);
 }
<?php

chdir(getcwd());
require './vendor/autoload.php';
use zaboy\scheduler\FileSystem\CommandLineWorker;
use zaboy\scheduler\DataStore\UTCTime;
use zaboy\rest\DataStore\DataStoreAbstract;
$commandLineWorker = new CommandLineWorker();
$options = $commandLineWorker->getCallOptions($_SERVER['argv']);
$delay = isset($options['delay']) ?: 2;
sleep($delay);
$container = (include './config/container.php');
/** @var DataStoreAbstract $dataStore */
$dataStore = $container->get('pids_datastore');
$itemData = ['pid' => posix_getpid(), 'startedAt' => UTCTime::getUTCTimestamp(), 'scriptName' => "testWorkerCallback.php", 'timeout' => 30];
$dataStore->create($itemData);