tobento/app-schedule
最新稳定版本:2.0
Composer 安装命令:
composer require tobento/app-schedule
包简介
App schedule support.
README 文档
README
Schedule support for the app using the Schedule Service.
Table of Contents
Getting Started
Add the latest version of the app schedule project running this command.
composer require tobento/app-schedule
Requirements
- PHP 8.4 or greater
Documentation
App
Check out the App Skeleton if you are using the skeleton.
You may also check out the App to learn more about the app in general.
Schedule Boot
The schedule boot does the following:
- implements schedule interfaces
- boots the Console Boot and adds schedule commands to console
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();
If you are not using the App Skeleton check out the App Console Boot section as you might adjust the app file.
Scheduling Tasks
You can schedule tasks in severval ways:
Using the app
You may use the app on method to schedule tasks only if the schedule is requested.
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();
Using a boot
You may create a boot for scheduling tasks:
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); }); } }
Check out the Schedule Service - Schedule section to learn more about it.
Furthermore, all the Tasks and Task Parameters are ready to use without any requirements.
Running Scheduled Tasks
To run the scheduled tasks, add a cron configuration entry to your server that runs the schedule:run command every minute.
* * * * * cd /path-to-your-project && php app schedule:run >> /dev/null 2>&1
Credits
统计信息
- 总下载量: 18
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-12-01