GithubHelp home page GithubHelp logo

jufemaiz / whenever-elasticbeanstalk Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dignoe/whenever-elasticbeanstalk

10.0 3.0 5.0 84 KB

Allows you to run cron jobs easily on one or all AWS Elastic Beanstalk instances.

License: MIT License

Ruby 100.00%

whenever-elasticbeanstalk's Introduction

WARNING

AWS has recently made changes to their EB ENV variables that are catastrophic for much of the rails deployment approaches for EB. This includes whenever-elasticbeanstalk. We are investigating how we can address these issues. Please see Issue 18 for further details. Will update when a resolution is available.

Whenever::Elasticbeanstalk

Whenever-elasticbeanstalk is an extension gem to Whenever that automatically ensures that one instance in an AWS Elastic Beanstalk environment is set as leader. This allows you to run cron jobs on all instances, or just on the leader. This is required since Elastic Beanstalk may start or stop any instance as it scales up or down.

Installation

Add this line to your application's Gemfile:

gem 'whenever-elasticbeanstalk'

And then execute:

$ bundle

Or install it yourself as:

$ gem install whenever-elasticbeanstalk

Getting started

$ cd /apps/my-great-project
$ wheneverize-eb .

This will create an initial config/schedule.rb file for you with the ensure_leader job set to run every minute. It will also create a .ebextensions/cron.config file that will automatically choose a leader on environment initialization, and start up Whenever with the correct leader role. Lastly, it creates the config/whenever-elasticbeanstalk.yml file that will contain your AWS credentials for retrieving your environment information.

Manually updating schedule

If you are already using Whenever, running wheneverize-eb . won't overwrite your config/schedule.rb file. You'll need to add the following lines in order for your environment to always have one leader.

every 1.minute do
  command "cd /var/app/current && bundle exec ensure_one_cron_leader"
end

EC2 Instance IAM Role Permissions

In order for the scripts to work, you need to ensure that the EC2 Instance Role has access to EC2 instances and tags (further reading at AWS Documentation ). Ensure that your EC2 instance has at a minimum the following permissions:

Example policy:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Action": [
        "ec2:DescribeInstanceAttribute",
        "ec2:DescribeInstanceStatus",
        "ec2:DescribeInstances",
        "ec2:DescribeTags",
        "ec2:CreateTags"
      ],
      "Resource": [
        "*"
      ],
      "Effect": "Allow"
    }
  ]
}

Make sure to add the RACK_ENV environment variable to your environment if you haven't already done so. This variable is not created automatically by AWS. You can add the following line to your .elasticbeanstalk/optionsettings.appname-env file:

RACK_ENV=staging

Usage

For config/schedule.rb usage, please see the documentation for the Whenever gem.

Run a task on only one instance

To run a task only on one instance, assign the task to the leader role.

every :day, :at => "12:30am", :roles => [:leader] do
	runner "MyModel.task_to_run_nightly_only_on_one_instance"
end

Run a task on all instances

To run a task on all instance, omit the roles option.

every 1.minute do
	command "touch $EB_CONFIG_APP_SUPPORT/.cron_check"
end

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

whenever-elasticbeanstalk's People

Contributors

jufemaiz avatar dignoe avatar lime avatar obrientimothya avatar

Stargazers

Rory Hughes avatar Kotaro Itoyama avatar Abhiroop Bhatnagar avatar Sadik Ay avatar Jeremie Weldin avatar Naoto Yokoyama avatar Junya Wako avatar Kai De Sutter avatar Jason Winn avatar Uriel Juliatti avatar

Watchers

 avatar James Cloos avatar Kesha Antonov avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.