mbm-rafal / laravel-single-dispatch
Laravel 处理器扩展,用于维护重复作业
1.0.0
2017-05-28 19:22 UTC
Requires
- php: >=5.5.9
This package is not auto-updated.
Last update: 2024-09-20 23:03:39 UTC
README
laravel dispatcher 扩展,不允许在同一队列上重复执行相同的作业。该功能的动机是为了在不使用特定作业等待处理的情况下,不滥用资源,另一个作业不应被排队。
特性
- 允许捕获并忽略重复作业
要求
安装 https://laravel.net.cn/docs/5.4/queues
安装
在 composer.json 中要求 mbm-rafal/laravel-single-dispatch
包并更新您的依赖项。
$ composer require mbm-rafal/laravel-single-dispatch
$ composer update
发布迁移文件
$ php artisan vendor:publish --provider="MBM\Bus\BusServiceProvider" --force
运行迁移
$ php artisan migrate
使用方法
要使用此扩展,您必须更新由 Dispatcher::class
提供的资源。为此,简单地在 app/config.php
中切换 BusServiceProvider
。
// Illuminate\Bus\BusServiceProvider::class, \MBM\Bus\BusServiceProvider::class,
您必须在 AppServiceProvider
中应用代码到队列事件
# Manage processed jobs Queue::after(function (JobProcessed $event) { app(\MBM\Bus\Dispatcher::class)->unregister($event->job); }); Queue::failing(function (JobFailed $event) { app(\MBM\Bus\Dispatcher::class)->unregister($event->job); });
如果您想允许作业重复,请在 Job 类定义中添加接口
use Illuminate\Contracts\Queue\ShouldQueue; use \MBM\Bus\AllowDuplicates class CustomJob implements ShouldQueue, AllowDuplicates { // Code }
许可证
在 MIT 许可证下发布,请参阅 LICENSE。