Exemplo n.º 1
0
 /**
  * @param int|float $timeStart
  * @param int|float $step
  * @param mixed|null $options
  * @return mixed|null
  * @throws TaskException
  */
 public function activate($timeStart, $step, $options = [])
 {
     if (!$this->data['active']) {
         return null;
     }
     $schedule = $this->getSchedule();
     $timeline = new Timeline();
     $maxStep = $timeline->determineStep($schedule);
     if ($maxStep < $step) {
         throw new TaskException("The step determined from query to Timeline DataStore is less\n                than step given from parameters: {$maxStep} < {$step}");
     }
     $schedule = $this->addTickLimit($schedule, $timeStart, $step);
     $matches = $timeline->query($schedule);
     // If match was found runs his callback
     $result = null;
     if (count($matches)) {
         $result = call_user_func_array($this->getCallback(), $options);
     }
     return $result;
 }
Exemplo n.º 2
0
 /**
  * Tick callback which called from Ticker
  *
  * @param $tickId
  * @param $step
  * @throws SchedulerException
  * @throws \zaboy\scheduler\Callback\CallbackException
  */
 public function processTick($tickId, $step)
 {
     $rqlParser = new RqlParser();
     foreach ($this->filters as $filter) {
         // Parses rql-query expression
         $rqlQueryObject = $rqlParser->decode($filter['rql']);
         // Step value determined in Timeline DataStore
         if ($this->timelineDs->determineStep($rqlQueryObject) < $step) {
             throw new SchedulerException("The step determined from query to timeline DataStore is less than step given from Ticker");
         }
         // Adds time limits and executes query to timeline
         $rqlQueryObject = $this->addTickLimit($rqlQueryObject, $tickId, $step);
         $matches = $this->timelineDs->query($rqlQueryObject);
         // If mathces were found runs their callbacks
         if (count($matches)) {
             /** @var CallbackInterface $instance */
             $instance = $this->callbackManager->get($filter['callback']);
             $instance->call(['tick_id' => $tickId, 'step' => $step]);
         }
     }
 }
Exemplo n.º 3
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);
 }