2017 © Pedro Peláez
 

library multi-server-scheduling

This package extends Laravel's native Command Event class to add functionality that prevents events from overlapping when ran in multi server environments. This is achieved using Laravel Cache

image

madlab/multi-server-scheduling

This package extends Laravel's native Command Event class to add functionality that prevents events from overlapping when ran in multi server environments. This is achieved using Laravel Cache

  • Friday, June 23, 2017
  • by nickashley
  • Repository
  • 4 Watchers
  • 7 Stars
  • 3,437 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 8 % Grown

The README.md

Multi Server Scheduling

This package extends Laravel's native task scheduling to include the ability to lock events and block them from overlapping when in a multi webserver environment., (*1)

It works similarly to Laravel's withoutOverlapping feature, except the lockfile is written to Cache as opposed to the local filesystem, and each server generates a unique key to lock the command., (*2)

In order to prevent a condition where a short-running command's lock doesn't last long enough, we are implementing a minimum 10 second break between the completion of the command and its next execution time, so if a command runs every minute but takes between 50 and 59 seconds to complete, the next command will be delayed one more minute. We also automatically expire any locks after 1 hour., (*3)

You may also enable logging to Laravel's logfile, so that you can ensure things are working correctly., (*4)

Installation

$ composer require madlab/multi-server-scheduling

The new scheduler uses Laravel's cache to track which server is currently executing an event. You must make sure you have configured a cache driver that is distributed and accessible by all servers (like memcache or redis)., (*5)

Now we want to change the default schedule IoC to use this alternate one. In app\Console\Kernel.php add the following function:, (*6)


use Illuminate\Contracts\Cache\Repository as Cache; use madlab\MultiServerScheduling\Schedule as MultiServerSchedule; /** * Define the application's command schedule. * * @return void */ protected function defineConsoleSchedule() { $this->app->instance( Schedule::class, $schedule = new MultiServerSchedule( $this->app[Cache::class], MultiServerSchedule::LOG_LEVEL_ABANDONED ) ); $this->schedule($schedule); }

Usage

When composing your schedule, simply add "withoutOverlappingCache()" to the command, i.e., (*7)

$schedule->command('inspire')
    ->daily()
    ->withoutOverlappingCache();

This will prevent multiple servers from executing the same event at the same time., (*8)

Logging

When intitializing the Scheduler in app\Console\Kernal.php, you may pass in 3 different logging levels: - LOG_LEVEL_NONE: logging is disabled - LOG_LEVEL_ABANDONED: a log will be written anytime a server tries to execute a task that has already been running for 10+ minutes - LOG_LEVEL_VERBOSE: most detailed, will log anytime a lock is attempted, obtained, or released, (*9)

Support

This was made by Nick Ashley at MadLab, LLC and if you need paid support you can contact us at MadLab.com., (*10)

The Versions

23/06 2017

dev-master

9999999-dev

This package extends Laravel's native Command Event class to add functionality that prevents events from overlapping when ran in multi server environments. This is achieved using Laravel Cache

  Sources   Download

MIT

The Requires

 

by Nick Ashley

laravel scheduler load balancing multi-server

05/02 2017

v1.1.0

1.1.0.0

This package extends Laravel's native Command Event class to add functionality that prevents events from overlapping when ran in multi server environments. This is achieved using Laravel Cache

  Sources   Download

MIT

The Requires

 

by Nick Ashley

laravel scheduler load balancing multi-server

27/01 2017

v1.0.2

1.0.2.0

This package extends Laravel's native Command Event class to add functionality that prevents events from overlapping when ran in multi server environments. This is achieved using Laravel Cache

  Sources   Download

MIT

The Requires

 

by Nick Ashley

laravel scheduler load balancing multi-server

30/09 2016

v1.0.1

1.0.1.0

This package extends Laravel's native Command Event class to add functionality that prevents events from overlapping when ran in multi server environments. This is achieved using Laravel Cache

  Sources   Download

MIT

The Requires

 

by Nick Ashley

laravel scheduler load balancing multi-server

28/09 2016

v1.0

1.0.0.0

This package extends Laravel's native Command Event class to add functionality that prevents events from overlapping when ran in multi server environments. This is achieved using Laravel Cache

  Sources   Download

MIT

The Requires

 

by Nick Ashley

laravel scheduler load balancing multi-server