Schedule a timer for execution.

@param TimerInterface $timer
498855
private function scheduleTimer(TimerInterface $timer)
    {
        $flags = Event::TIMEOUT;

        if ($timer->isPeriodic()) {
            $flags |= Event::PERSIST;
        }

        $event = new Event($this->eventBase, -1, $flags, $this->timerCallback, $timer);
        $this->timerEvents[$timer] = $event;

        $event->add($timer->getInterval());
    }
1361508
public function cancelTimer(TimerInterface $timer)
    {
        $this->emit('cancelTimer', [$timer]);

        return $this->loop->cancelTimer($timer);
    }
827551
protected function execute(InputInterface $input, OutputInterface $output)
  {
    $scheduler = new Runner();
    $schedule = new Kernel();
    $schedule->run($scheduler);

    // run application commands
    (new SystemScheduler)->run($scheduler);

    $this->autoload_plugins($scheduler);

    $scheduler->run();
  }
788706
protected function callTimeout(TimerInterface $timer)
    {

        // if we have any more schedules remaining, then schedule a new task
        if ($timer->getNextExpiration() != null && !$timer->isInRetry()) {
            $timer->scheduleTimeout(false);
        }

        // invoke the timeout on the timed object
        $timer->getTimerService()->getTimedObjectInvoker()->callTimeout($timer);
    }
1301422
protected function execute(InputInterface $input, OutputInterface $output)
    {
        /** @var CronService $cronService */
        $cronService = $this->getContainer()->get(CronService::class);
        $crons = $cronService->listCronsStatus();
        $cronRows = [];

        foreach ($crons as $cron) {
            $cronStatus = '';
            if ($cron instanceof EdgarCron) {
                switch ($cron->getStatus()) {
                    case EdgarCronRepository::STATUS_INIT:
                        $cronStatus = $this->translator->trans('Init', [], 'edgarcron');
                        break;
                    case EdgarCronRepository::STATUS_OK:
                        $cronStatus = $this->translator->trans('OK', [], 'edgarcron');
                        break;
                    case EdgarCronRepository::STATUS_ERROR:
                        $cronStatus = $this->translator->trans('Error', [], 'edgarcron');
                        break;
                    default:
                        $cronStatus = '';
                        break;
                }
            }

            $cronRows[] = [
                $cron->getAlias(),
                $cron instanceof EdgarCron ? $cron->getQueued()->format('d-m-Y H:i') : false,
                $cron instanceof EdgarCron ? $cron->getStarted()->format('d-m-Y H:i') : false,
                $cron instanceof EdgarCron ? $cron->getEnded()->format('d-m-Y H:i') : false,
                $cronStatus,
            ];
        }

        $table = new Table($output);
        $table
            ->setHeaders(['Cron Alias', 'Queued', 'Started', 'Ended', 'Status'])
            ->setRows($cronRows);
        $table->render();
    }
959448
public static void removeTimer(ScheduledTimer timer) {
    Preconditions.checkNotNull(timer, "timer");
    try (LockResource r = new LockResource(sLock)) {
      ScheduledTimer removedTimer = sTimers.remove(timer.getThreadName());
      Preconditions.checkNotNull(removedTimer, "sTimers should contain %s", timer.getThreadName());
      Preconditions.checkState(removedTimer == timer,
          "sTimers should contain the timer being removed");
    }
  }
903653
protected function addTimer(\Erebot\TimerInterface $timer)
    {
        $bot = $this->connection->getBot();
        return $bot->addTimer($timer);
    }
621013
public function incrementTimer($name, $time) {
        if (!isset($this->timers[$name])) {
            $this->timers[$name] = 0;
        }
        $this->timers[$name] += $this->getTime() - $time;
    }
1079445
protected function setStarted($time = null)
    {
        $this->started = $time ?: microtime(true);
        $this->setState(RunInterface::STATE_RUNNING);
    }
417004
public function setValue($value)
    {
        if (is_array($value) && isset($value[0]) && $value[0] instanceof DateTimeInterface) {
            $this->setDateTimes($value);
        } elseif ($value instanceof DateTimeInterface) {
            $this->setDateTimes([$value]);
        } else {
            parent::setValue($value);
        }
    }
1198680
public function captureStart(EventInterface $event)
    {
        ++$this->index;

        $time = microtime(true);

        $eventName = $event->getName();
        if ($eventName) {
            $this->timers[$eventName] = ['start' => $time, 'stop' => $time];

            return;
        }
        $this->timers[$this->index] = ['start' => $time, 'stop' => $time];
    }
1367733
private function setTimers($forceRegenerate = false)
    {
        $start = time();

        // If there is no starting point, restart all over again
        if (!$this->has('timer.start', 'session') || $forceRegenerate) {
            $this->set('timer.start', $start, 'session');
            $this->set('timer.last', $start, 'session');
            $this->set('timer.now', $start, 'session');
        }

        // Set current timers
        $this->set('timer.last', $this->get('timer.now', null, 'session'), 'session');
        $this->set('timer.now', time(), 'session');
    }
1186634
public function setNextSchedule($scheduler)
    {
        $scheduler->next_run_due = $this->getNextRunDue($scheduler->schedule, $scheduler->timezone);
        $scheduler->next_check_due = $this->getNextCheckDue($scheduler->schedule, $scheduler->timezone, $scheduler->alert_run_time_greater_than);
        $scheduler->save();
    }
350519
public function setDateTime(DateTimeInterface $dateTime)
    {
        $this->clearCachedValueIf($this->getCachedValue() != $dateTime->format(DateTime::RFC2822));
        if ($dateTime instanceof DateTime) {
            $immutable = new DateTimeImmutable('@'.$dateTime->getTimestamp());
            $dateTime = $immutable->setTimezone($dateTime->getTimezone());
        }
        $this->dateTime = $dateTime;
    }
1046862
public function iterate($timeout)
    {

        // call parent method and sleep for the default timeout
        parent::iterate($timeout);

        // create the requested timer instance
        $this->synchronized(function ($self) {

            // create the timer, only if we're NOT dispatched
            if ($self->dispatched === false) {
                $self->timer = Timer::builder()
                    ->setNewTimer(true)
                    ->setId(Uuid::uuid4()->__toString())
                    ->setInitialDate($self->initialExpiration)
                    ->setRepeatInterval($self->intervalDuration)
                    ->setInfo($self->info)
                    ->setPersistent($self->persistent)
                    ->setTimerState(TimerState::CREATED)
                    ->setTimedObjectId($self->timerService->getTimedObjectInvoker()->getTimedObjectId())
                    ->build($self->timerService);

                // we're dispatched now
                $self->dispatched = true;
            }

        }, $this);

        // profile the size of the sessions
        if ($this->profileLogger) {
            $this->profileLogger->debug(
                sprintf('Size of session pool is: %d', sizeof($this->sessionPool))
            );
        }
    }
1316906
protected function defineCommandSchedule(Schedule $schedule, array $definition)
    {
        $arguments = $definition['arguments'] ?? [];

        $event = $schedule->command($definition['command'], $arguments);

        $this->configureEvent($event, $definition);
    }
333896
static public function start($name) {
    static::$timers[$name]['start'] = microtime(TRUE);
    static::$timers[$name]['count'] = isset(static::$timers[$name]['count']) ? ++static::$timers[$name]['count'] : 1;
  }