Download the PHP package madlab/multi-server-scheduling without Composer
On this page you can find all versions of the php package madlab/multi-server-scheduling. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download madlab/multi-server-scheduling
More information about madlab/multi-server-scheduling
Files in madlab/multi-server-scheduling
Package multi-server-scheduling
Short Description 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
License MIT
Informations about the package multi-server-scheduling
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.
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.
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.
You may also enable logging to Laravel's logfile, so that you can ensure things are working correctly.
Installation
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).
Now we want to change the default schedule IoC to use this alternate one. In app\Console\Kernel.php add the following function:
Usage
When composing your schedule, simply add "withoutOverlappingCache()" to the command, i.e.
This will prevent multiple servers from executing the same event at the same time.
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
Support
This was made by Nick Ashley at MadLab, LLC and if you need paid support you can contact us at MadLab.com.