repository = $repository; $this->runnerService = $runnerService; } /** * Set the time that this schedule should be run at. This will override the time * defined on the schedule itself. Useful for triggering one-off task runs. * * @param \DateTimeInterface $time * @return $this */ public function setRunTimeOverride(DateTimeInterface $time) { $this->runTimeOverride = $time; return $this; } /** * Process a schedule and push the first task onto the queue worker. * * @param \Pterodactyl\Models\Schedule $schedule * * @throws \Pterodactyl\Exceptions\Model\DataValidationException * @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException */ public function handle(Schedule $schedule) { $this->repository->loadTasks($schedule); $formattedCron = sprintf('%s %s %s * %s', $schedule->cron_minute, $schedule->cron_hour, $schedule->cron_day_of_month, $schedule->cron_day_of_week ); $this->repository->update($schedule->id, [ 'is_processing' => true, 'next_run_at' => $this->getRunAtTime($formattedCron), ]); $task = $schedule->getRelation('tasks')->where('sequence_id', 1)->first(); $this->runnerService->handle($task); } /** * Get the timestamp to store in the database as the next_run time for a schedule. * * @param string $formatted * @return string */ private function getRunAtTime(string $formatted) { if (! is_null($this->runTimeOverride)) { return $this->runTimeOverride->format(Chronos::ATOM); } return CronExpression::factory($formatted)->getNextRunDate()->format(Chronos::ATOM); } }