All Projects → FoxxMD → laravel-elasticbeanstalk-cron

FoxxMD / laravel-elasticbeanstalk-cron

Licence: MIT license
Ensure one instance within an EB environment is running Laravel's Scheduler

Programming Languages

PHP
23972 projects - #3 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to laravel-elasticbeanstalk-cron

transferwisely
Batch process using transfer-wise API to automatically track, detect and book transfers for you at better rates.
Stars: ✭ 20 (-63.64%)
Mutual labels:  cron
cronode
Cron for Node.js with expressive code
Stars: ✭ 15 (-72.73%)
Mutual labels:  cron
sidecloq
Recurring / Periodic / Scheduled / Cron job extension for Sidekiq
Stars: ✭ 81 (+47.27%)
Mutual labels:  cron
chadburn
Chadburn is a scheduler alternative to cron, built on Go and designed for Docker environments.
Stars: ✭ 54 (-1.82%)
Mutual labels:  cron
slacker
Simple smtp email server which redirects emails to slack.
Stars: ✭ 24 (-56.36%)
Mutual labels:  cron
rhythm
Time-based job scheduler for Apache Mesos
Stars: ✭ 30 (-45.45%)
Mutual labels:  cron
howto
Dumping ground for various HowTo documents that I produce
Stars: ✭ 58 (+5.45%)
Mutual labels:  cron
dron
What if cron and systemd had a baby?
Stars: ✭ 30 (-45.45%)
Mutual labels:  cron
btrfs-backup
A simple, flexible script for versioned backups using btrfs and rsync
Stars: ✭ 59 (+7.27%)
Mutual labels:  cron
gymbox-bot
Simplify the booking of a gymbox class.
Stars: ✭ 21 (-61.82%)
Mutual labels:  cron
watchman
📆 更夫(watchman)是一款可视化的定时任务配置 Web 工具,麻麻不用担心我漏掉任何更新啦!
Stars: ✭ 40 (-27.27%)
Mutual labels:  cron
Diglett
Diglett is a cron management system that manage all your cron jobs without modifying crontab. Handles locking, logging, error emails, and more.
Stars: ✭ 13 (-76.36%)
Mutual labels:  cron
jobs.config
Scheduling recurring jobs.config builder/validator for Velo by Wix
Stars: ✭ 18 (-67.27%)
Mutual labels:  cron
webping
🚦 Python script to monitor web pages.
Stars: ✭ 20 (-63.64%)
Mutual labels:  cron
GnusSolution
A complete working solution of gnus+offlineimap+dovecot+msmtp+cron
Stars: ✭ 18 (-67.27%)
Mutual labels:  cron
node-cron-expression
Declarative functional cron expression builder
Stars: ✭ 17 (-69.09%)
Mutual labels:  cron
delayed-notifications-for-gravity-forms
Set delayed notifications for your gravity forms in easy steps
Stars: ✭ 26 (-52.73%)
Mutual labels:  cron
ansible-role-elasticsearch-curator
Ansible Role - Elasticsearch Curator
Stars: ✭ 31 (-43.64%)
Mutual labels:  cron
actions-aws-eb
Elastic beanstalk cli custom action
Stars: ✭ 39 (-29.09%)
Mutual labels:  elasticbeanstalk
cron-time
Javascript Cron Time Expressions
Stars: ✭ 58 (+5.45%)
Mutual labels:  cron

Laravel 5 - 9.x Task Scheduler with Elastic Beanstalk

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.

Amazon Linux 1 deprecation

Amazon Linux 1 (AL1) is going to be unsupported soon, it is advised to migrate to use Amazon Linux 2 (AL2) https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/using-features.migration-al.html Starts from this release will only support AL2, please use previous releases for use in AL1

How Does It Work?

Glad you asked! The below process is completely automated and only requires that you publish the .platform folder to the root of your application.

1. Use Elastic Beanstalk's Advanced Configuration to run CRON setup commands

EB applications since AL2 can contain platform hooks that provides advanced configuration for an EB environment, called .platform.

This package provides a configuration file that runs two commands on deployment (every instance initialization) that setup the conditions needed to run the Task Scheduler on one instance:

2. Run 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)

3. Run Leader Selection aws:configure:leader

This is the Leader Selection command. It does the following:

  • Get the Id of the Instance this deployment is running on
  • Get the EnvironmentName of this Instance. (When running in an EB environment all EC2 instances have the same EnvironmentName)
  • Get all running EC2 instances with that EnvironmentName
  • Find the earliest launched instance

If this instance is the earliest launched then it is deemed the Leader and runs system:start:cron

4. Run 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.

That's it!

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.

Installation

Require this package, for Amazon Linux 2,

composer require "foxxmd/laravel-elasticbeanstalk-cron"

or for Amazon Linux 1,

composer require "foxxmd/laravel-elasticbeanstalk-cron@^0.9"

After adding the package, add the ServiceProvider to the providers array in config/app.php (for Laravel 5.4 or lower)

\FoxxMD\LaravelElasticBeanstalkCron\ElasticBeanstalkCronProvider::class

Then, publish the .platform folder and configuration file

php artisan vendor:publish --tag=ebcron

Don't forget to add +x permission to the EB Platform Hooks scripts

find .platform -type f -iname "*.sh" -exec chmod +x {} +

Configuration

In order for Leader Selection to run a few environmental variables must be present:

  • USE_CRON = true -- Must be set in order for Leader Selection to occur. (This can be used to prevent Selection from occurring on undesired environments IE Workers, etc.)
  • AWS_ACCESS_KEY_ID -- Needed for read-only access to EC2 client
  • AWS_SECRET_ACCESS_KEY -- Needed for read-only access to EC2 client
  • AWS_REGION -- Sets which AWS region when looking using the EC2 client, defaults to us-east-1 if not set.

These can be included in your .env or, for EB, in the environment's configuration section.

Contributing

Make a PR for some extra functionality and I will happily accept it :)

License

This package is licensed under the MIT license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].