├── pint.json ├── .github ├── dependabot.yml └── workflows │ └── test.yml ├── .editorconfig ├── config └── schedule.php ├── src ├── Listeners │ ├── ScheduledTaskFailedListener.php │ ├── ScheduledTaskFinishedListener.php │ └── ScheduledTaskStartingListener.php ├── Repositories │ └── Models │ │ └── Schedule.php ├── Commands │ └── Command.php └── Providers │ └── LaravelServiceProvider.php ├── composer.json ├── LICENSE ├── database └── migrations │ └── create_schedules_table.php.stub └── README.md /pint.json: -------------------------------------------------------------------------------- 1 | { 2 | "preset": "laravel" 3 | } -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "composer" 4 | directory: "/" 5 | schedule: 6 | interval: "daily" 7 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 4 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = false 10 | 11 | [*.{vue,js,scss}] 12 | charset = utf-8 13 | indent_style = space 14 | indent_size = 2 15 | end_of_line = lf 16 | insert_final_newline = true 17 | trim_trailing_whitespace = true 18 | 19 | [*.md] 20 | trim_trailing_whitespace = false -------------------------------------------------------------------------------- /config/schedule.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * This source file is subject to the MIT license that is bundled 9 | * with this source code in the file LICENSE. 10 | */ 11 | 12 | return [ 13 | 'table' => 'schedules', 14 | 15 | 'model' => \Jiannei\Schedule\Laravel\Repositories\Models\Schedule::class, 16 | 17 | 'output' => [ 18 | 'path' => storage_path('logs'), 19 | ], 20 | ]; 21 | -------------------------------------------------------------------------------- /src/Listeners/ScheduledTaskFailedListener.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * This source file is subject to the MIT license that is bundled 9 | * with this source code in the file LICENSE. 10 | */ 11 | 12 | namespace Jiannei\Schedule\Laravel\Listeners; 13 | 14 | use Illuminate\Console\Events\ScheduledTaskFailed; 15 | 16 | class ScheduledTaskFailedListener 17 | { 18 | public function handle(ScheduledTaskFailed $event) 19 | { 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Listeners/ScheduledTaskFinishedListener.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * This source file is subject to the MIT license that is bundled 9 | * with this source code in the file LICENSE. 10 | */ 11 | 12 | namespace Jiannei\Schedule\Laravel\Listeners; 13 | 14 | use Illuminate\Console\Events\ScheduledTaskFinished; 15 | 16 | class ScheduledTaskFinishedListener 17 | { 18 | public function handle(ScheduledTaskFinished $event) 19 | { 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Listeners/ScheduledTaskStartingListener.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * This source file is subject to the MIT license that is bundled 9 | * with this source code in the file LICENSE. 10 | */ 11 | 12 | namespace Jiannei\Schedule\Laravel\Listeners; 13 | 14 | use Illuminate\Console\Events\ScheduledTaskStarting; 15 | 16 | class ScheduledTaskStartingListener 17 | { 18 | public function handle(ScheduledTaskStarting $event) 19 | { 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "jiannei\/laravel-schedule", 3 | "description": "More flexible way to manage your Laravel schedule tasks.", 4 | "keywords": [ 5 | "laravel","schedule" 6 | ], 7 | "license": "MIT", 8 | "authors": [ 9 | { 10 | "name": "jiannei", 11 | "email": "longjian.huang@foxmail.com" 12 | } 13 | ], 14 | "autoload": { 15 | "psr-4": { 16 | "Jiannei\\Schedule\\Laravel\\": "src" 17 | } 18 | }, 19 | "extra": { 20 | "laravel": { 21 | "providers": [ 22 | "Jiannei\\Schedule\\Laravel\\Providers\\LaravelServiceProvider" 23 | ] 24 | } 25 | }, 26 | "require-dev": { 27 | "orchestra/testbench": "^10.2.1", 28 | "pestphp/pest": "^4.0", 29 | "laravel/pint": "^1.18.3" 30 | }, 31 | "scripts": { 32 | "test": "vendor/bin/pest", 33 | "style": "vendor/bin/pint" 34 | }, 35 | "config": { 36 | "allow-plugins": { 37 | "pestphp/pest-plugin": true 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 jiannei 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/Repositories/Models/Schedule.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * This source file is subject to the MIT license that is bundled 9 | * with this source code in the file LICENSE. 10 | */ 11 | 12 | namespace Jiannei\Schedule\Laravel\Repositories\Models; 13 | 14 | use Illuminate\Database\Eloquent\Model; 15 | 16 | class Schedule extends Model 17 | { 18 | protected $fillable = [ 19 | 'description', 'command', 'parameters', 'expression', 'active', 'timezone', 20 | 'environments', 'without_overlapping', 'on_one_server', 'in_background', 'in_maintenance_mode', 21 | 'output_file_path', 'output_append', 'output_email', 'output_email_on_failure', 22 | ]; 23 | 24 | protected $casts = [ 25 | 'active' => 'boolean', 26 | 'on_one_server' => 'boolean', 27 | 'in_background' => 'boolean', 28 | 'in_maintenance_mode' => 'boolean', 29 | 'output_append' => 'boolean', 30 | 'output_email_on_failure' => 'boolean', 31 | ]; 32 | 33 | /** 34 | * Scope a query to only include active schedule. 35 | * 36 | * @param \Illuminate\Database\Eloquent\Builder $query 37 | * @return \Illuminate\Database\Eloquent\Builder 38 | */ 39 | public function scopeActive($query) 40 | { 41 | return $query->where('active', 1); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /database/migrations/create_schedules_table.php.stub: -------------------------------------------------------------------------------- 1 | id(); 19 | $table->string('description')->default(''); 20 | $table->string('command')->default(''); 21 | $table->string('parameters')->nullable(); 22 | $table->string('expression')->default(''); 23 | $table->boolean('active')->default(false); 24 | $table->string('timezone'); 25 | $table->json('environments')->nullable(); 26 | $table->unsignedInteger('without_overlapping')->default(0); 27 | $table->boolean('on_one_server')->default(false); 28 | $table->boolean('in_background')->default(false); 29 | $table->boolean('in_maintenance_mode')->default(false); 30 | $table->string('output_file_path')->nullable(); 31 | $table->boolean('output_append')->default(false); 32 | $table->string('output_email')->nullable(); 33 | $table->boolean('output_email_on_failure')->default(false); 34 | $table->timestamps(); 35 | 36 | $table->index('active'); 37 | $table->index('command'); 38 | }); 39 | } 40 | 41 | /** 42 | * Reverse the migrations. 43 | * 44 | * @return void 45 | */ 46 | public function down() 47 | { 48 | Schema::dropIfExists(Config::get('schedule.table', 'schedules')); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: Test 2 | 3 | on: 4 | push: 5 | branches: [ main ] 6 | pull_request: 7 | branches: [ main ] 8 | 9 | jobs: 10 | tests: 11 | name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} 12 | runs-on: ${{ matrix.os }} 13 | strategy: 14 | fail-fast: false 15 | matrix: 16 | os: [ ubuntu-latest ] 17 | php: [8.2] 18 | laravel: [ 11.* ] 19 | dependency-version: [ prefer-stable ] 20 | include: 21 | - laravel: 11.* 22 | testbench: 9.* 23 | 24 | steps: 25 | - name: Checkout code 26 | uses: actions/checkout@v4 27 | 28 | - name: Validate composer.json and composer.lock 29 | run: composer validate --strict 30 | 31 | - name: Cache Composer packages 32 | uses: actions/cache@v4 33 | with: 34 | path: vendor 35 | key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} 36 | restore-keys: | 37 | ${{ runner.os }}-php- 38 | 39 | - name: Setup PHP 40 | uses: shivammathur/setup-php@v2 41 | with: 42 | php-version: ${{ matrix.php }} 43 | extensions: curl, mbstring, zip, pcntl, sqlite, pdo_sqlite, iconv 44 | coverage: none 45 | 46 | - name: Install dependencies - L${{ matrix.laravel }} 47 | run: | 48 | composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update 49 | composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction 50 | 51 | - name: Execute tests 52 | run: vendor/bin/pest -------------------------------------------------------------------------------- /src/Commands/Command.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * This source file is subject to the MIT license that is bundled 9 | * with this source code in the file LICENSE. 10 | */ 11 | 12 | namespace Jiannei\Schedule\Laravel\Commands; 13 | 14 | use Illuminate\Console\Command as IlluminateCommand; 15 | use Illuminate\Support\Facades\Config; 16 | use Symfony\Component\Console\Input\InputOption; 17 | use Symfony\Component\Process\Process; 18 | 19 | abstract class Command extends IlluminateCommand 20 | { 21 | public function __construct() 22 | { 23 | $scheduleEnum = Config::get('schedule.enum'); 24 | 25 | $this->description = $scheduleEnum::fromValue($this->name)->description; 26 | 27 | parent::__construct(); 28 | 29 | $this->defineGlobalOptions(); 30 | } 31 | 32 | protected function defineGlobalOptions(): void 33 | { 34 | foreach ($this->getGlobalOptions() as $options) { 35 | $this->addOption(...array_values($options)); 36 | } 37 | } 38 | 39 | protected function getGlobalOptions(): array 40 | { 41 | // array($name, $shortcut, $mode, $description, $defaultValue) 42 | return [ 43 | ['queue', '-Q', InputOption::VALUE_OPTIONAL, 'Set the desired queue for the job', null], 44 | ['connection', '-C', InputOption::VALUE_OPTIONAL, 'Set the desired connection for the job.', null], 45 | ]; 46 | } 47 | 48 | /** 49 | * 调度 Job. 50 | * 51 | * @param mixed $job 52 | * @return \Laravel\Lumen\Bus\PendingDispatch|mixed 53 | */ 54 | protected function dispatch($job) 55 | { 56 | $pendingDispatch = dispatch($job); 57 | 58 | if ($queue = $this->option('queue')) { 59 | $pendingDispatch->onQueue($queue); 60 | } 61 | 62 | if ($connection = $this->option('connection')) { 63 | $pendingDispatch->onConnection($connection); 64 | } 65 | 66 | return $pendingDispatch; 67 | } 68 | 69 | /** 70 | * 执行 shell 命令. 71 | */ 72 | protected function exec(string $command): ?int 73 | { 74 | return Process::fromShellCommandline($command) 75 | ->setTty($this->isTtySupported()) 76 | ->setWorkingDirectory(base_path()) 77 | ->setTimeout(null) 78 | ->setIdleTimeout(null) 79 | ->mustRun(function ($type, $buffer) { 80 | $this->output->write($buffer); 81 | }) 82 | ->getExitCode(); 83 | } 84 | 85 | protected function isTtySupported(): bool 86 | { 87 | return config('app.env') !== 'testing' && Process::isTtySupported(); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # laravel-schedule 2 | 3 | > ⏱ More flexible way to manage your Laravel schedule tasks. - 更灵活地管理 Laravel 应用中的任务调度。 4 | 5 | ![StyleCI](https://github.styleci.io/repos/377056763/shield?style=flat&branch=main) 6 | [![Latest Stable Version](https://poser.pugx.org/jiannei/laravel-schedule/v)](https://packagist.org/packages/jiannei/laravel-schedule) 7 | [![Total Downloads](https://poser.pugx.org/jiannei/laravel-schedule/downloads)](https://packagist.org/packages/jiannei/laravel-schedule) 8 | [![Monthly Downloads](https://poser.pugx.org/jiannei/laravel-schedule/d/monthly)](https://packagist.org/packages/jiannei/laravel-schedule) 9 | [![Version](https://poser.pugx.org/jiannei/laravel-schedule/version)](https://packagist.org/packages/jiannei/laravel-schedule) 10 | [![License](https://poser.pugx.org/jiannei/laravel-schedule/license)](https://packagist.org/packages/jiannei/laravel-schedule) 11 | 12 | ## 社区讨论文章 13 | 14 | - [是时候使用 Lumen 8 + API Resource 开发项目了!](https://learnku.com/articles/45311) 15 | - [教你更优雅地写 API 之「路由设计」](https://learnku.com/articles/45526) 16 | - [教你更优雅地写 API 之「规范响应数据」](https://learnku.com/articles/52784) 17 | - [教你更优雅地写 API 之「枚举使用」](https://learnku.com/articles/53015) 18 | - [教你更优雅地写 API 之「记录日志」](https://learnku.com/articles/53669) 19 | - [教你更优雅地写 API 之「灵活地任务调度」](https://learnku.com/articles/58403) 20 | 21 | ## 功能 22 | 23 | - 通过 schedules 数据表来管理任务调度 24 | - 支持开启关闭调度任务 25 | - 支持通过数据表来更新任务执行间隔 26 | - 支持 laravel 任务调度时的 timezone、environments、withoutOverlapping、onOneServer、runInBackground、evenInMaintenanceMode、Output(任务输出到文件、邮件)配置 27 | 28 | Tips: 使用该扩展只是多了一种可以基于数据表维护任务调度的方式,不会破坏原先 Laravel 定义任务调度的方式,两种方式甚至可以组合使用。 29 | 30 | ## 安装和配置 31 | 32 | - 安装 33 | 34 | ```shell 35 | $ composer require jiannei/laravel-schedule -vvv 36 | ``` 37 | 38 | - 发布服务 39 | 40 | ```shell 41 | $ php artisan vendor:publish --provider="Jiannei\Schedule\Laravel\Providers\LaravelServiceProvider" 42 | ``` 43 | 44 | - 执行迁移 45 | 46 | ```shell 47 | php artisan migrate 48 | ``` 49 | 50 | ## 使用 51 | 52 | 为了能够更容易地集成到各种项目中,该扩展包并未直接提供一个 web 界面来维护 schedules 数据表,你可以按你的方式把 schedules 的配置维护进去就好。 53 | 54 | 举例说明项目中的使用方式: 55 | 56 | - 维护应用程序中的 schedule 调度配置到 schedules 数据表 57 | 58 | ```sql 59 | INSERT INTO `schedules` (`id`, `description`, `command`, `parameters`, `expression`, `active`, `timezone`, `environments`, `without_overlapping`, `on_one_server`, `in_background`, `in_maintenance_mode`, `output_file_path`, `output_append`, `output_email`, `output_email_on_failure`, `created_at`, `updated_at`) VALUES (1, '爬取 Github daily 趋势', 'github:trending', NULL, '*/10 * * * *', 1, 'Asia/Shanghai', NULL, 0, 0, 1, 1, 'github_trending.log', 1, NULL, 0, NULL, NULL); 60 | INSERT INTO `schedules` (`id`, `description`, `command`, `parameters`, `expression`, `active`, `timezone`, `environments`, `without_overlapping`, `on_one_server`, `in_background`, `in_maintenance_mode`, `output_file_path`, `output_append`, `output_email`, `output_email_on_failure`, `created_at`, `updated_at`) VALUES (2, '爬取 Github weekly 趋势', 'github:trending', '--since=weekly', '59 23 * * *', 1, 'Asia/Shanghai', NULL, 0, 0, 1, 1, 'github_trending.log', 1, NULL, 0, NULL, NULL); 61 | INSERT INTO `schedules` (`id`, `description`, `command`, `parameters`, `expression`, `active`, `timezone`, `environments`, `without_overlapping`, `on_one_server`, `in_background`, `in_maintenance_mode`, `output_file_path`, `output_append`, `output_email`, `output_email_on_failure`, `created_at`, `updated_at`) VALUES (3, '爬取 Github monthly 趋势', 'github:trending', '--since=monthly', '59 23 * * *', 1, 'Asia/Shanghai', NULL, 0, 0, 1, 1, 'github_trending.log', 1, NULL, 0, NULL, NULL); 62 | ``` 63 | 64 | > 说明: 65 | > - command,应用程序中已经定义并且需要自动调度的 command 66 | > - parameters,对应 command 执行时指定的参数 67 | > - expression,执行时间间隔,cron 表达式 68 | > - active,0 开启,1 关闭 69 | > - output_file_path,指定 command 的输出的文件路径 70 | > - output_append,command 输出到文件时是否进行追加 71 | > - output_email,command 输出发送邮件 72 | > - output_email_on_failure,只在 command 执行失败时发送输出到邮件 73 | > - 其他参数均可以在 laravel schedule 文档中找到相应的函数说明:https://laravel.com/docs/8.x/scheduling#introduction 74 | 75 | - 通过`php artisan schedule:list`检验是否配置成功 76 | 77 | ```shell 78 | +------------------------------------------------------------------------+--------------+--------------------------+----------------------------+ 79 | | Command | Interval | Description | Next Due | 80 | +------------------------------------------------------------------------+--------------+--------------------------+----------------------------+ 81 | | '/www/server/php/80/bin/php' 'artisan' github:trending | */10 * * * * | 爬取 Github daily 趋势 | 2021-06-22 21:40:00 +08:00 | 82 | | '/www/server/php/80/bin/php' 'artisan' github:trending --since=weekly | 59 23 * * * | 爬取 Github weekly 趋势 | 2021-06-22 23:59:00 +08:00 | 83 | | '/www/server/php/80/bin/php' 'artisan' github:trending --since=monthly | 59 23 * * * | 爬取 Github monthly 趋势 | 2021-06-22 23:59:00 +08:00 | 84 | +------------------------------------------------------------------------+--------------+--------------------------+----------------------------+ 85 | ``` 86 | 87 | - 重启应用程序中的 `php artisan schedule:run` 88 | 89 | 以上,基于 schedules 数据表来管理调度任务就完成了。 90 | 91 | ## 协议 92 | 93 | MIT 许可证(MIT)。有关更多信息,请参见[协议文件](LICENSE)。 -------------------------------------------------------------------------------- /src/Providers/LaravelServiceProvider.php: -------------------------------------------------------------------------------- 1 | 7 | * 8 | * This source file is subject to the MIT license that is bundled 9 | * with this source code in the file LICENSE. 10 | */ 11 | 12 | namespace Jiannei\Schedule\Laravel\Providers; 13 | 14 | use Cron\CronExpression; 15 | use Illuminate\Console\Events\ScheduledTaskFailed; 16 | use Illuminate\Console\Events\ScheduledTaskFinished; 17 | use Illuminate\Console\Events\ScheduledTaskStarting; 18 | use Illuminate\Console\Scheduling\Schedule; 19 | use Illuminate\Database\QueryException; 20 | use Illuminate\Support\Facades\Config; 21 | use Illuminate\Support\Facades\Validator; 22 | use Illuminate\Support\ServiceProvider; 23 | use Illuminate\Support\Str; 24 | use Jiannei\Schedule\Laravel\Listeners\ScheduledTaskFailedListener; 25 | use Jiannei\Schedule\Laravel\Listeners\ScheduledTaskFinishedListener; 26 | use Jiannei\Schedule\Laravel\Listeners\ScheduledTaskStartingListener; 27 | 28 | class LaravelServiceProvider extends ServiceProvider 29 | { 30 | public function boot(): void 31 | { 32 | $this->extendValidationRules(); 33 | 34 | $this->setupConfig(); 35 | 36 | if ($this->app->runningInConsole()) { 37 | $this->setupMigration(); 38 | 39 | $this->listenEvents(); 40 | 41 | $this->app->resolving(Schedule::class, function ($schedule) { 42 | $this->schedule($schedule); 43 | }); 44 | } 45 | } 46 | 47 | protected function listenEvents(): void 48 | { 49 | $this->app['events']->listen(ScheduledTaskStarting::class, ScheduledTaskStartingListener::class); 50 | $this->app['events']->listen(ScheduledTaskFinished::class, ScheduledTaskFinishedListener::class); 51 | $this->app['events']->listen(ScheduledTaskFailed::class, ScheduledTaskFailedListener::class); 52 | } 53 | 54 | protected function extendValidationRules(): void 55 | { 56 | Validator::extend('cron_expression', function ($attribute, $value, $parameters, $validator) { 57 | return CronExpression::isValidExpression($value); 58 | }); 59 | } 60 | 61 | protected function setupConfig(): void 62 | { 63 | $configPath = dirname(__DIR__, 2).'/config/schedule.php'; 64 | 65 | if ($this->app->runningInConsole()) { 66 | $this->publishes([$configPath => config_path('schedule.php')], 'schedule'); 67 | } 68 | 69 | $this->mergeConfigFrom($configPath, 'schedule'); 70 | } 71 | 72 | protected function setupMigration(): void 73 | { 74 | $this->publishes([ 75 | __DIR__.'/../../database/migrations/create_schedules_table.php.stub' => database_path('migrations/'.date('Y_m_d_His').'_create_schedules_table.php'), 76 | ], 'migrations'); 77 | } 78 | 79 | /** 80 | * Prepare schedule from tasks. 81 | */ 82 | protected function schedule(Schedule $schedule): void 83 | { 84 | $commands = app(\Illuminate\Contracts\Console\Kernel::class)->all(); 85 | 86 | try { 87 | $schedules = app(Config::get('schedule.model'))->active()->get(); 88 | } catch (QueryException $exception) { 89 | $schedules = collect(); 90 | } 91 | 92 | $schedules->each(function ($item) use ($schedule, $commands) { 93 | $event = $schedule->command($item->command.' '.$item->parameters); 94 | $event->cron($item->expression) 95 | ->name($item->description) 96 | ->timezone($item->timezone); 97 | 98 | $callbacks = ['skip', 'when', 'before', 'after', 'onSuccess', 'onFailure']; 99 | foreach ($callbacks as $callback) { 100 | if (isset($commands[$item->command]) && method_exists($commands[$item->command], $callback)) { 101 | $event->$callback($commands[$item->command]->$callback($event, $item)); 102 | } 103 | } 104 | 105 | if ($item->environments) { 106 | $event->environments($item->environments); 107 | } 108 | 109 | if ($item->without_overlapping) { 110 | $event->withoutOverlapping($item->without_overlapping); 111 | } 112 | 113 | if ($item->on_one_server) { 114 | $event->onOneServer(); 115 | } 116 | 117 | if ($item->in_background) { 118 | $event->runInBackground(); 119 | } 120 | 121 | if ($item->in_maintenance_mode) { 122 | $event->evenInMaintenanceMode(); 123 | } 124 | 125 | if ($item->output_file_path) { 126 | if ($item->output_append) { 127 | $event->appendOutputTo(Config::get('schedule.output.path').Str::start($item->output_file_path, DIRECTORY_SEPARATOR)); 128 | } else { 129 | $event->sendOutputTo(Config::get('schedule.output.path').Str::start($item->output_file_path, DIRECTORY_SEPARATOR)); 130 | } 131 | } 132 | 133 | if ($item->output_email) { 134 | if ($item->output_email_on_failure) { 135 | $event->emailOutputOnFailure($item->output_email); 136 | } else { 137 | $event->emailOutputTo($item->output_email); 138 | } 139 | } 140 | }); 141 | } 142 | } 143 | --------------------------------------------------------------------------------