evolution-cms / evolution

Welcome to the new evolution of MODX Evolution!
GNU General Public License v3.0
260 stars 96 forks source link

[ADD] Schedule. #2112

Closed Seiger closed 1 year ago

Seiger commented 1 year ago

Створення консольної команди описано https://github.com/evolution-cms/example-package#console. Щоб додати розклад, потрібно в файл команди додати метод schedule().

/**
     * Define the command's schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    public function schedule(Schedule $schedule)
    {
        $schedule->command(static::class)->everyFiveMinutes();
    }

В методі boot() сервіс провайдера ініціалізувати розклад.

if (count($this->commands)) {
            $this->app->booted(function () {
                $this->defineConsoleSchedule();
            });
        }

Додати необхідні методи в файл сервіс провайдера

/**
     * Define the application's command schedule.
     *
     * @note check timezones list timezone_identifiers_list()
     *
     * @return void
     */
    protected function defineConsoleSchedule()
    {
        $this->app->singleton(Schedule::class, function ($app) {
            return tap(new Schedule('Europe/Kyiv'), function ($schedule) {
                $this->schedule($schedule->useCache('file'));
            });
        });
    }
  /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    public function schedule(Schedule $schedule)
    {
        foreach ($this->commands as $command) {
            (new $command)->schedule($schedule);
        }
    }

Налаштувати запуск крон * * * * * cd /path-to-your-project/core && php artisan schedule:run >> /dev/null 2>&1

Детальніше тут https://laravel.com/docs/9.x/scheduling