m-alsafadi/laravel-queue

Laravel Custom Queue System

1.1.0 2022-08-02 17:51 UTC

This package is auto-updated.

Last update: 2024-04-30 00:45:47 UTC


README

Laravel custom queue system.

Installation

  1. Use composer:
composer require m-alsafadi/laravel-queue
  1. Add to .env file:
LARAVEL_QUEUE_ENABLED=true
LARAVEL_QUEUE_DISK=local
LARAVEL_QUEUE_SINGLE_PROC=true
LARAVEL_QUEUE_CACHE=false
LARAVEL_QUEUE_LOG_CHANNEL=stack
  1. Add trait to your model (optional):
use \MAlsafadi\LaravelQueue\Traits\TLaravelQueueModel;
  1. Create job:
php artisan laravel:queue:job UserJob
  1. Modify handle method in your job at \App\Jobs\UserJob
  2. Start the worker:
    1. Via artisan command:
    php artisan larave:queue:start
    1. Via file:
    php laravel-queue

Publish config:

php artisan vendor:publish --provider=MAlsafadi\\LaravelQueue\\Providers\\LaravelQueueProvider

How to add job to queue:

  1. Via your job:
\App\Jobs\UserJob::addJob($model, $valid_at, $arguments, $name);
  1. Via your model:
\App\Models\User::find(1)->addJob(\App\Jobs\UserJob::class, $valid_at, $arguments, $name);
  1. Via Laravel Queue:
LaravelQueue::addJob($model, \App\Jobs\UserJob::class, $valid_at, $arguments, $name);

Info: Attribute $name is optional.

Commands:

  1. Laravel Queue Helper:
php artisan laravel:queue
  1. Create New Laravel Queue Job:
php artisan laravel:queue:job
  1. Start Laravel Queue Worker:
php artisan laravel:queue:start

License

The Laravel framework is open-sourced software licensed under the MIT license.

The Laravel Queue is open-sourced software licensed under the MIT license.