Package Data | |
---|---|
Maintainer Username: | FoxxMD |
Maintainer Contact: | FoxxMD@users.noreply.github.com (FoxxMD) |
Package Create Date: | 2016-05-24 |
Package Last Update: | 2023-12-04 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-30 03:02:09 |
Package Statistics | |
---|---|
Total Downloads: | 274,755 |
Monthly Downloads: | 893 |
Daily Downloads: | 31 |
Total Stars: | 60 |
Total Watchers: | 10 |
Total Forks: | 16 |
Total Open Issues: | 3 |
Ensure one instance in an Elastic Beanstalk environment is running Laravel's Scheduler
A common problem many people have encountered with Amazon's Elastic Beanstalk is maintaining a single instance in an environment that runs Laravel's Task Scheduler. Difficulties arise because auto-scaling does not guarantee any instance is run indefinitely and there are no "master-slave" relationships within an environment to differentiate one instance from the rest.
Although Amazon has provided a solution it involves setting up a worker tier and then, potentially, creating new routes/methods for implementing the tasks that need to be run. Yuck!
This package provides a simple, zero-setup solution for maintaining one instance within an Elastic Beanstalk environment that runs the Task Scheduler.
Glad you asked! The below process is completely automated and only requires that you publish the .ebextensions
folder to the root of your application.
EB applications can contain a folder that provides advanced configuration for an EB environment, called .ebextensions
.
This package provides a configuration file that runs two commands on deployment (every instance initialization) that setup the conditions needed to run the Task Schedler on one instance:
system:start:leaderselection
This is the first command that is run on deployment. It configures the instance's Cron to run Leader Selection at a configured interval (default = 5 minutes)
aws:configure:leader
This is the Leader Selection command. It does the following:
EnvironmentName
of this Instance. (When running in an EB environment all EC2 instances have the same EnvironmentName
)EnvironmentName
If this instance is the earliest launched then it is deemed the Leader and runs system:start:cron
system:start:cron
This command is run only if the current instance running Leader Selection is the Leader. It inserts another entry in the instance's Cron to run Laravel's Scheduler.
Now only one instance, the earliest launched, will have the scheduler inserted into its Cron. If that instance is terminated by auto-scaling a new Leader will be chosen within 5 minutes (or the configured interval) from the remaining running instances.
Require this package
composer require "foxxmd/laravel-elasticbeanstalk-cron"
After adding the package, add the ServiceProvider to the providers array in config/app.php
\FoxxMD\LaravelElasticBeanstalkCron\ElasticBeanstalkCronProvider::class
Then, publish the .ebextensions folder and configuration file.
php artisan vendor:publish --tag=ebcron
In order for Leader Selection to run a few environmental variables must be present:
us-east-1
if not set.These can be included in your .env or, for EB, in the environment's configuration section.
Make a PR for some extra functionality and I will happily accept it :)
This package is licensed under the MIT license.