Download the PHP package mpbarlow/laravel-queue-debouncer without Composer

On this page you can find all versions of the php package mpbarlow/laravel-queue-debouncer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-queue-debouncer

Laravel Queue Debouncer

Easy queue job debouncing

Requirements

Note: v2.0 requires at least Laravel 6. For Laravel 5.5 ..< 6.0 support, check out v1.0.2

Installation

composer require mpbarlow/laravel-queue-debouncer

Background

This package allows any queue job or chain in your Laravel application to be debounced, meaning that no matter how many times it’s dispatched within the specified timeout window, it will only run once.

For example, imagine you dispatch a job to rebuild a cache every time a record is updated, but the job is resource intensive. Debouncing the job with a five minute wait would ensure that the cache is only rebuilt once, five minutes after you finish making changes.

Usage

Debounced jobs can largely be treated like any other dispatched job. The debouncer takes two arguments, the actual $job you want to run, and the $wait period.

As with a regular dispatch, $job can be either a class implementing Illuminate\Foundation\Bus\Dispatchable, a chain, or a closure. $wait accepts any argument that the delay method on a dispatch accepts (i.e. a DateTimeInterface or a number of seconds).

The debouncer returns an instance of Illuminate\Foundation\Bus\PendingDispatch, meaning the debouncing process itself may be assigned to a different queue or otherwise manipulated.

Calling the debouncer

There are several ways to use the debouncer:

Dependency Injection

Facade

Helper function

Trait

When monitoring the queue, you will see an entry for the package’s internal dispatcher each time the debounced job is queued, but the job itself will only run once, when the final wait time has expired.

For example, assuming the following code was ran at exactly 9am:

you should expect the following activity on your queue:

Customising Behaviour

This package provides a few hooks to customise things to your needs. To override the default behaviour, you should publish the config file:

This will copy queue_debouncer.php to your config directory.

Cache key provider

To identify the job being debounced, the package generates a unique key in the cache for each job type.

Two cache key providers are included:

Alternatively, you can provide your own class or closure to cover any other behaviour you might need:

If you provide a class, it should implement Mpbarlow\LaravelQueueDebouncer\Contracts\CacheKeyProvider. Please note that your class is responsible for fetching and prepending the cache prefix should you still desire this behaviour.

Class-based providers may be globally registered as the default provider by changing the cache_key_provider value in the config. Alternatively, you may "hot-swap" the provider using the usingUniqueIdentifierProvider method:

If you provide a closure, it may only be be hot-swapped:

Closure providers automatically have their value prefixed by the configured cache_prefix. To override this behaviour, implement a class-based provider that accepts a closure in its constructor, then calls it in its getKey method.

Unique identifier provider

Each time a debounced job is dispatched, a unique identifier is stored against the cache key for the job. When the wait time expires, if that identifier matches the value of the current job, the debouncer knows that no more recent instances of the job have been dispatched, and therefore it is safe to dispatch it.

The default implementation produces a UUID v4 for each dispatch. If you need to override this you may do so in the same manner as cache key providers, globally registering a class under the unique_identifier_provider key in the config, or hot-swapping using the usingUniqueIdentifierProvider method:

Class-based providers should implement Mpbarlow\LaravelQueueDebouncer\Contracts\UniqueIdentifierProvider.

Licence

This package is open-source software provided under the The MIT License.


All versions of laravel-queue-debouncer with dependencies

PHP Build Version
Package Version
Requires php Version ^7.2|^8.0
laravel/framework Version ^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
opis/closure Version ^3.6
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package mpbarlow/laravel-queue-debouncer contains the following files

Loading the files please wait ....