From 35944018d72c99ca91e31cbf61736fbebb806437 Mon Sep 17 00:00:00 2001 From: Naman Gupta <01namangupta@gmail.com> Date: Wed, 9 May 2018 23:07:34 +0530 Subject: [PATCH 1/2] Added whenever gem for easily writing and deploying cron jobs --- Gemfile | 2 ++ README.md | 10 ++++++++++ config/schedule.rb | 20 ++++++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 config/schedule.rb diff --git a/Gemfile b/Gemfile index d2e9a165b2..a937a245ce 100644 --- a/Gemfile +++ b/Gemfile @@ -12,6 +12,8 @@ gem 'responders', '~> 2.0' # for Rails 4.2 gem 'turbolinks' +# Whenever provides a clear syntax for writing and deploying cron jobs +gem 'whenever', require: false # run with `bundle install --without production` or `bundle install --without mysql` to exclude this group :mysql, :production do diff --git a/README.md b/README.md index 75ea4aff14..d4ceed1ad3 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,16 @@ Please read and abide by our [Code of Conduct](https://publiclab.org/conduct); o 12. Wheeeee! You're up and running! Log in with test usernames "user", "moderator", or "admin", and password "password". 13. Run `rake test` to confirm that your install is working properly. For some setups, you may see warnings even if test pass; [see this issue](https://github.com/publiclab/plots2/issues/440) we're working to resolve. +## How to start and modify cron jobs + +1. We are using whenever gem to schedule cron jobs [Whenever](https://github.com/javan/whenever) +2. All the cron jobs are written in easy ruby syntax using this gem and can be found in config/schedule.rb. +2. Go to the config/schedule.rb file to create and modify the cron jobs. +3. [Click here](https://github.com/javan/whenever) to know about how to write cron jobs. +4. After updating config/schedule.rb file run the command `whenever --update-crontab` to update the cron jobs. +5. To see the installed list of cron jobs use command `crontab -l` +6. For more details about this gem, visit the official repository of whenever gem. + ### Bundle exec For some, it will be necessary to prepend your gem-related commands with `bundle exec`, for example, `bundle exec passenger start`; adding `bundle exec` ensures you're using the version of passenger you just installed with Bundler. `bundle exec rake db: setup`, `bundle exec rake db: seed` are other examples of where this might be necessary. diff --git a/config/schedule.rb b/config/schedule.rb new file mode 100644 index 0000000000..de75cf9d48 --- /dev/null +++ b/config/schedule.rb @@ -0,0 +1,20 @@ +# Use this file to easily define all of your cron jobs. +# +# It's helpful, but not entirely necessary to understand cron before proceeding. +# http://en.wikipedia.org/wiki/Cron + +# Example: +# +# set :output, "/path/to/my/cron_log.log" +# +# every 2.hours do +# command "/usr/bin/some_great_command" +# runner "MyModel.some_method" +# rake "some:great:rake:task" +# end +# +# every 4.days do +# runner "AnotherModel.prune_old_records" +# end + +# Learn more: http://github.com/javan/whenever From 3310805edbb6274f02abb70c080d01a869888582 Mon Sep 17 00:00:00 2001 From: Sebastian Silva Date: Thu, 10 May 2018 00:06:00 -0500 Subject: [PATCH 2/2] Add cron for whenever gem --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 3fc5b20b6d..20c6465e4b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,7 +18,7 @@ ENV PHANTOMJS_VERSION 2.1.1 # > /etc/apt/sources.list # Install dependencies -RUN apt-get update -qq && apt-get install -y bundler libmysqlclient-dev ruby-rmagick libfreeimage3 nodejs-legacy npm wget procps +RUN apt-get update -qq && apt-get install -y bundler libmysqlclient-dev ruby-rmagick libfreeimage3 nodejs-legacy npm wget procps cron RUN wget https://github.com/Medium/phantomjs/releases/download/v$PHANTOMJS_VERSION/phantomjs-$PHANTOMJS_VERSION-linux-x86_64.tar.bz2 -O /tmp/phantomjs-$PHANTOMJS_VERSION-linux-x86_64.tar.bz2; tar -xvf /tmp/phantomjs-$PHANTOMJS_VERSION-linux-x86_64.tar.bz2 -C /opt ; cp /opt/phantomjs-$PHANTOMJS_VERSION-linux-x86_64/bin/* /usr/local/bin/ RUN npm install -g bower