jeffreyvanrossum / wp-job-scheduler
WordPress 任务调度和执行的便捷包装器。
0.1.3
2024-03-01 14:35 UTC
Requires
- php: ^8.0
- woocommerce/action-scheduler: ^3.7
Requires (Dev)
- laravel/pint: ^1.4
- phpcompatibility/php-compatibility: *
- spatie/ray: ^1.36
- spatie/x-ray: ^1.1
README
WP Job Scheduler
🚧 此包仍在开发中
此包旨在使 WordPress 中的任务调度和执行更加容易。
受 Laravel 语法启发,并使用来自 WooCommerce 的 Action Scheduler,以提高可靠性。
安装
composer require jeffreyvanrossum/wp-job-scheduler
使用
设置
在您的主题或插件中添加
WPJobScheduler::instance() ->projectRootPath(__DIR__) ->scheduler(function() { ExampleJob::schedule('hourly'); }) ->boot();
调度单个任务
ExampleJob::dispatch();
您可以在任务调度之前传递一个回调来对任务进行一些更改
ExampleJob::dispatch(function($job) { $job->withDelay(30); });
您还可以传递一些初始构造函数参数
ExampleJob::dispatch(function($job) { $job->withDelay(30); }, ['foo' => 'bar']);
示例任务
class ExampleJob implements Jobable { use IsJob, Schedulable, Dispatchable; public function handle() { // the actual handling of the job } public function before(): void { // before the job has been handled } public function after(): void { // after the job has been handled } public function catch(Throwable $e): void { // do something with exception } }
贡献者
许可
MIT。请参阅 许可文件 以获取更多信息。