/** * 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]); } } }
/** * @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; }