示例#1
0
 /**
  * {@inherit}
  *
  * {@inherit}
  */
 public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
 {
     $config = $container->get('config')[self::TICKER_SERVICE_NAME];
     $callbackManager = new CallbackManager($container);
     if (!isset($config['hop']['callback'])) {
         throw new CallbackException("The necessary parameter \"hop/callback\" does not exist.");
     }
     if (!isset($config['tick']['callback'])) {
         throw new CallbackException("The necessary parameter \"tick/callback\" does not exist.");
     }
     /** @var \zaboy\scheduler\Callback\Interfaces\CallbackInterface $hopCallback */
     $hopCallback = $callbackManager->get($config['hop']['callback']);
     /** @var \zaboy\scheduler\Callback\Interfaces\CallbackInterface $tickCallback */
     $tickCallback = $callbackManager->get($config['tick']['callback']);
     $ticker = new Ticker($tickCallback, $hopCallback, $config);
     return $ticker;
 }
示例#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]);
         }
     }
 }