reyesoft/reactive-laravel-jobs 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

reyesoft/reactive-laravel-jobs

最新稳定版本:11.0.1

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

Debounce diagram, from RxJs documentation

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.

Throttle diagram, from RxJs documentation

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

统计信息

  • 总下载量: 8.77k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: proprietary
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固