reyesoft/reactive-laravel-jobs

Reactive Laravel Jobs
11,061 1
Install
composer require reyesoft/reactive-laravel-jobs
Latest Version:11.0.1
PHP:^8.1
License:proprietary
Last Updated:Jun 5, 2025
Links: GitHub  ·  Packagist
Maintainer: pablorsk

Reactive Laravel Jobs

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

Related Packages

sonnn/laravel-slack-bot

Sends a message to Slack when something goes wrong with your Laravel application...

51 2
masnun/joinjobs

A Laravel package that allows scheduling certain actions upon job completion or...

52 3
nicolasmahe/laravel-slack-output

Sends a message to Slack when something goes wrong with your Laravel application...

42,975 27
salopot/laravel-queue-walker

Laravel queue walker, process all jobs on a queue.

531 2
dan/email

A simple email implementation I use in many of my Laravel ~5.1 packages.

11 2