Git Product home page Git Product logo

mklef121 / queuebutler Goto Github PK

View Code? Open in Web Editor NEW

This project forked from web-chefs/queuebutler

0.0 0.0 0.0 62 KB

Laravel Artisan queue helper commands that makes it possible to run job queues using the Scheduler without the need for installing and running a Queue Daemon or installing SupervisorD, allowing for effectively running Job Queues from a cron via the Scheduler in any environment even shared hosting

License: MIT License

PHP 100.00%

queuebutler's Introduction

QueueButler

Latest Version on Packagist Software License Total Downloads Build Status

Laravel Artisan commands that make it easy to run job queues using the Scheduler without the need for installing for running the Queue Daemon or installing Supervisor.

This is ideal for shared hosting or situations where you are not fully in control of the services or management of your hosting infrastructure and all you have access to is a Cron.

Versions

Confirmed to be working:

  • Laravel 5.3
  • Laravel 5.4
  • Laravel 5.5

Install

Via Composer

$ composer require web-chefs/queue-butler

Add Service Provider to config/app.php

'providers' => [
   // Other Service Providers
   WebChefs\QueueButler\QueueButlerServiceProvider::class,
];

Usage

Artisan command

Run queue:batch artisan command, supports many of the same options as queue:work. Two additional options time-limit in seconds (defaults to 60 seconds) and 'job-limit' (defaults to 100) need to be set based on your Scheduling setup.

Example:

Run batch for 4 min 30 seconds or 1000 jobs, then stop.

artisan queue:batch --time-limit=270 --job-limit=1000

Scheduler

In your App\Console\Kernel.php in the schedule() method add your queue:batch commands.

Example:

Run batch every minute for 50 seconds or 100 jobs in the background using runInBackground(), then stop. Prevent overlapping batches running simultaneously with withoutOverlapping().

$schedule->command('queue:batch --queue=default,something,somethingelse --time-limit=50 --job-limit=100')
         ->everyMinute()
         ->runInBackground()
         ->withoutOverlapping();

If your application is processing a large number of jobs for multiple queues, it is recommended setting up different batch scheduler commands per queue.

Because job queue processing is a long running process setting runInBackground() is highly recommended, else each queue:batch command will hold up all scheduled preceding items setup to run after it.

The Scheduler requires a Cron to be setup. See Laravel documentation for details how the Scheduler works.

withoutOverlapping() and Mutex cache expiry

When using withoutOverlapping() a cache Mutex is used to keep track of running jobs. The default cache expiry is 1440 minutes (24 hours).

If your batch process is interrupted the scheduler will ignore the task for the time of the expiry and you will have no jobs processing for 24 hours. The only way to resolve this is to clear the cache or manually remove the batch processes cache entry.

To prevent long running cache expiries it is advised to match your cache cache expiry time with your task frequency.

// Create Batch Job Queue Processor Task
$scheduledEvent = $schedule->command('queue:batch --queue=default,something,somethingelse --time-limit=55 --job-limit=100');

// Match cache expiry with frequency
// Set cache mutex expiry to One min (default is 1440)
$scheduledEvent->expiresAt = 1;
$scheduledEvent->everyMinute()
               ->withoutOverlapping()
               ->runInBackground();

Standards

  • psr-1
  • psr-2
  • psr-4

Change log

Please see CHANGELOG for more information on what has changed recently.

Contributing

All code submissions will only be evaluated and accepted as pull-requests. If you have any questions or find any bugs please feel free to open an issue.

Credits

License

The MIT License (MIT). Please see License File for more information.

queuebutler's People

Contributors

jfossey avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.