tobento / app-schedule
应用调度支持。
1.0.0
2023-12-01 14:26 UTC
Requires
- php: >=8.0
- guzzlehttp/guzzle: ^7.8
- symfony/process: ^4.4|^5.4|^6.0
- tobento/app: ^1.0.7
- tobento/app-cache: ^1.0
- tobento/app-console: ^1.0
- tobento/app-event: ^1.0
- tobento/app-mail: ^1.0
- tobento/service-schedule: ^1.0
Requires (Dev)
- phpunit/phpunit: ^9.5
- tobento/service-filesystem: ^1.0.5
- vimeo/psalm: ^4.0
README
使用调度服务对应用进行调度支持。
目录
入门指南
使用此命令添加应用调度项目的最新版本。
composer require tobento/app-schedule
需求
- PHP 8.0 或更高版本
文档
应用
如果您使用的是骨架,请查看 应用骨架。
您还可以查看 应用,了解更多关于应用的信息。
调度启动
调度启动执行以下操作:
- 实现调度接口
- 启动 控制台启动 并向控制台添加调度命令
use Tobento\App\AppFactory; use Tobento\Service\Schedule\ScheduleInterface; use Tobento\Service\Schedule\ScheduleProcessorInterface; use Tobento\Service\Schedule\TaskProcessorInterface; // Create the app $app = (new AppFactory())->createApp(); // Add directories: $app->dirs() ->dir(realpath(__DIR__.'/../'), 'root') ->dir(realpath(__DIR__.'/../app/'), 'app') ->dir($app->dir('app').'config', 'config', group: 'config') ->dir($app->dir('root').'public', 'public') ->dir($app->dir('root').'vendor', 'vendor'); // Adding boots $app->boot(\Tobento\App\Schedule\Boot\Schedule::class); $app->booting(); // Implemented interfaces: $schedule = $app->get(ScheduleInterface::class); $scheduleProcessor = $app->get(ScheduleProcessorInterface::class); $taskProcessor = $app->get(TaskProcessorInterface::class); // Run the app $app->run();
如果您不使用 应用骨架,请查看 应用控制台启动 部分,您可能需要调整 app
文件。
安排任务
您可以通过多种方式安排任务:
使用应用
您可以使用应用的 on
方法来安排任务,但仅当请求调度时。
use Tobento\App\AppFactory; use Tobento\Service\Schedule\ScheduleInterface; // Create the app $app = (new AppFactory())->createApp(); // Add directories: $app->dirs() ->dir(realpath(__DIR__.'/../'), 'root') ->dir(realpath(__DIR__.'/../app/'), 'app') ->dir($app->dir('app').'config', 'config', group: 'config') ->dir($app->dir('root').'public', 'public') ->dir($app->dir('root').'vendor', 'vendor'); // Adding boots: $app->boot(\Tobento\App\Schedule\Boot\Schedule::class); // Adding tasks: $app->on(ScheduleInterface::class, static function(ScheduleInterface $schedule): void { $schedule->task($task); }); // Run the app $app->run();
使用启动
您可以创建用于安排任务的启动
use Tobento\App\Boot; use Tobento\App\Schedule\Boot\Schedule; use Tobento\Service\Schedule\ScheduleInterface; class MyScheduleTasksBoot extends Boot { public const BOOT = [ // you may ensure the schedule boot. Schedule::class, ]; public function boot() { $this->app->on(ScheduleInterface::class, static function(ScheduleInterface $schedule): void { $schedule->task($task); }); } }
查看 调度服务 - 调度 部分以了解更多信息。
此外,所有 任务 和 任务参数 都已经准备好使用,无需任何要求。
运行计划任务
要运行计划中的任务,请向您的服务器添加一个 cron 配置条目,每分钟运行一次 schedule:run 命令。
* * * * * cd /path-to-your-project && php app schedule:run >> /dev/null 2>&1