2017 © Pedro Peláez
 

library multi-server-event

This package extends Laravel's native Command Event class to allow for managing events fired on the same system with multiple servers, preventing an event from firing more than once

image

jdavidbakr/multi-server-event

This package extends Laravel's native Command Event class to allow for managing events fired on the same system with multiple servers, preventing an event from firing more than once

  • Saturday, February 10, 2018
  • by jdavidbakr
  • Repository
  • 3 Watchers
  • 34 Stars
  • 75,576 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 14 Forks
  • 1 Open issues
  • 18 Versions
  • 9 % Grown

The README.md

Multi Server Event

Latest Version on Packagist ![Software License][ico-license] Total Downloads, (*1)

This package extends Laravel's native Event class to include the ability to block events from occurring aross multiple servers, as would be the case if you have a laravel instance behind a load balancer in an auto-scaling situation., (*2)

It uses a database table to track the currently running process, and each server generates a unique key to lock the command. 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., (*3)

NOTE: Laravel 5.6 now contains a function onOneServer() that solves the issue that this package was built to fix. Therefore, it is recommended that you use the core function instead of this package.

For Laravel < 5.4, please use version 1.X

Upgrading from version 1.X

If upgrading from version 1.X, please note the change in the defineConsoleSchedule() command in app\Console\Kernel.php., (*4)

Installation

$ composer require jdavidbakr/multi-server-event

The new event structure uses a database table to track which server is currently executing an event. You must create the database table using the provided migration. To do this, add the following to the $commands array in \App\Console\Kernel.php:, (*5)

\jdavidbakr\MultiServerEvent\Commands\MultiServerMigrationService::class,

then perform the migration, (*6)

php artisan make:migration:multi-server-event
php artisan migrate

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

/**
 * Define the application's command schedule.
 *
 * @return void
 */
protected function defineConsoleSchedule()
{
    $this->app->instance(
        Schedule::class,
        $schedule = new \jdavidbakr\MultiServerEvent\Scheduling\Schedule()
    );

    $this->schedule($schedule);
}

Usage

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

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

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

When composing your schedule, you can also ensure that cron is not stuck, simply add "ensureFinishedMultiServer()" to the command, i.e., (*10)

$schedule->command('inspire')
    ->daily()
    ->withoutOverlappingMultiServer()
    ->ensureFinishedMultiServer(30);

This will prevent from stuck commands during lost connection or deployment. Note, choose time to be enough to mark as "stuck", fox example, long running command should have bigger tolerance time. You can track such events how ofter it happens by binding listeners on EnsureCleanUpExecuted event, (*11)

Testing

phpunit

The Versions

10/02 2018

dev-master

9999999-dev

This package extends Laravel's native Command Event class to allow for managing events fired on the same system with multiple servers, preventing an event from firing more than once

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel scheduler load balancing multi-server

10/02 2018

2.0.5

2.0.5.0

This package extends Laravel's native Command Event class to allow for managing events fired on the same system with multiple servers, preventing an event from firing more than once

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel scheduler load balancing multi-server

17/08 2017

2.0.4

2.0.4.0

This package extends Laravel's native Command Event class to allow for managing events fired on the same system with multiple servers, preventing an event from firing more than once

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel scheduler load balancing multi-server

24/07 2017

2.0.3

2.0.3.0

This package extends Laravel's native Command Event class to allow for managing events fired on the same system with multiple servers, preventing an event from firing more than once

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel scheduler load balancing multi-server

01/05 2017

1.0.9

1.0.9.0

This package extends Laravel's native Command Event class to allow for managing events fired on the same system with multiple servers, preventing an event from firing more than once

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel scheduler load balancing multi-server

01/05 2017

2.0.2

2.0.2.0

This package extends Laravel's native Command Event class to allow for managing events fired on the same system with multiple servers, preventing an event from firing more than once

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel scheduler load balancing multi-server

06/02 2017

dev-version-1

dev-version-1

This package extends Laravel's native Command Event class to allow for managing events fired on the same system with multiple servers, preventing an event from firing more than once

  Sources   Download

MIT

The Requires

 

laravel scheduler load balancing multi-server

06/02 2017

1.0.8

1.0.8.0

This package extends Laravel's native Command Event class to allow for managing events fired on the same system with multiple servers, preventing an event from firing more than once

  Sources   Download

MIT

The Requires

 

laravel scheduler load balancing multi-server

06/02 2017

1.0.7

1.0.7.0

This package extends Laravel's native Command Event class to allow for managing events fired on the same system with multiple servers, preventing an event from firing more than once

  Sources   Download

MIT

The Requires

 

laravel scheduler load balancing multi-server

02/02 2017

2.0.1

2.0.1.0

This package extends Laravel's native Command Event class to allow for managing events fired on the same system with multiple servers, preventing an event from firing more than once

  Sources   Download

MIT

The Requires

 

laravel scheduler load balancing multi-server

02/02 2017

2.0.0

2.0.0.0

This package extends Laravel's native Command Event class to allow for managing events fired on the same system with multiple servers, preventing an event from firing more than once

  Sources   Download

MIT

The Requires

 

laravel scheduler load balancing multi-server

30/11 2016

1.0.6

1.0.6.0

This package extends Laravel's native Command Event class to allow for managing events fired on the same system with multiple servers, preventing an event from firing more than once

  Sources   Download

MIT

The Requires

 

laravel scheduler load balancing multi-server

11/11 2016

1.0.5

1.0.5.0

This package extends Laravel's native Command Event class to allow for managing events fired on the same system with multiple servers, preventing an event from firing more than once

  Sources   Download

MIT

The Requires

 

laravel scheduler load balancing multi-server

16/03 2016

1.0.4

1.0.4.0

This package extends Laravel's native Command Event class to allow for managing events fired on the same system with multiple servers, preventing an event from firing more than once

  Sources   Download

MIT

The Requires

 

laravel scheduler load balancing multi-server

18/11 2015

1.0.3

1.0.3.0

This package extends Laravel's native Command Event class to allow for managing events fired on the same system with multiple servers, preventing an event from firing more than once

  Sources   Download

MIT

The Requires

 

laravel scheduler load balancing multi-server

12/08 2015

1.0.2

1.0.2.0

This package extends Laravel's native Command Event class to allow for managing events fired on the same system with multiple servers, preventing an event from firing more than once

  Sources   Download

MIT

The Requires

 

laravel scheduler load balancing multi-server

12/08 2015

1.0.1

1.0.1.0

This package extends Laravel's native Command Event class to allow for managing events fired on the same system with multiple servers, preventing an event from firing more than once

  Sources   Download

MIT

The Requires

 

laravel scheduler load balancing multi-server

11/08 2015

1.0

1.0.0.0

This package extends Laravel's native Command Event class to allow for managing events fired on the same system with multiple servers, preventing an event from firing more than once

  Sources   Download