reyesoft/reactive-laravel-jobs
Composer 安装命令:
composer require reyesoft/reactive-laravel-jobs
包简介
Reactive Laravel Jobs
README 文档
README
Installation
composer require reyesoft/reactive-laravel-jobs
Features
- A same job dispatched various times can be grouped based on some value, like user_id.
- Delay time can be changed (takes last delay value).
Fantastic Laravel job types
Debounce Laravel Job
Dispatch delayed job only after delay value and passed without another job dispatched.
use Reyesoft\ReactiveLaravelJobs\Debounce\Debounceable; use Reyesoft\ReactiveLaravelJobs\Debounce\ShouldDebounce; final class DebouncedNotificationJob implements ShouldDebounce { use Debounceable; use Dispatchable; use Queueable; public $param1 = ''; public function __construct($param1) { $this->param1 = $param1; } public function uniqueId() { return $this->param1; } public function debouncedHandle(): void { echo PHP_EOL . $this->param1; } }
DebouncedNotificationJob::dispatchDebounced('You have 1 item.')->delay(5); DebouncedNotificationJob::dispatchDebounced('You have 2 items.')->delay(5); DebouncedNotificationJob::dispatchDebounced('You have 3 items.')->delay(5); sleep(10); DebouncedNotificationJob::dispatchDebounced('You have 4 items.')->delay(5); sleep(1); DebouncedNotificationJob::dispatchDebounced('You have 5 items.')->delay(5); // Do You have 3 items. You have 5 items.
Throttle Laravel Job
Dispatch delayed job, then ignores subsequent dispatched jobs for a duration determined by delay value, then repeats this process when.
On Laravel 9, it can be done with Unique Jobs.
use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Contracts\Queue\ShouldBeUnique; class ThrottledNotificationJob implements ShouldQueue, ShouldBeUnique { public $param1 = ''; public function __construct($param1) { $this->param1 = $param1; } /** * The number of seconds after which the job's unique lock * will be released. */ public $uniqueFor = 3600; public function uniqueId() { return $this->param1; } public function handle(): void { echo PHP_EOL . $this->param1; } }
ThrottledNotificationJob::dispatch('You have 1 item.')->delay(5); ThrottledNotificationJob::dispatch('You have 2 items.')->delay(5); ThrottledNotificationJob::dispatch('You have 3 items.')->delay(5); sleep(10); ThrottledNotificationJob::dispatch('You have 4 items.')->delay(5); sleep(1); ThrottledNotificationJob::dispatch('You have 5 items.')->delay(5); // Do You have 1 item. You have 4 items.
Testing
composer autofix
composer test
reyesoft/reactive-laravel-jobs 适用场景与选型建议
reyesoft/reactive-laravel-jobs 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10.44k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2022 年 06 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「jobs」 「reyesoft」 「laravel-jobs」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 reyesoft/reactive-laravel-jobs 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 reyesoft/reactive-laravel-jobs 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 reyesoft/reactive-laravel-jobs 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This library helps to generate QR codes for Crypto Address
Library to fix common errors in php and keep a clean code
This library helps to make payments through MercadoPago, even with QR
This module enables subscription to latest jobs by email
Super-simple, minimum abstraction Lever DATA API v1 wrapper in PHP with support for Laravel.
Alfabank REST API integration
统计信息
- 总下载量: 10.44k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 17
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: proprietary
- 更新时间: 2022-06-20