[Ruby on Rails] Solving the addiction when setting crontab using whenever in EC2

whenever is a Ruby on Rails gem and is often used when setting up crontab.

How to use

The usage is described in detail on the Github homepage, but the main ones are as follows.

** Add to Gemfile **


gem 'whenever', require: false

** Install **

bundle exec wheneverize .

** Check the contents of the schedule.rb file **


** Update crontab in development environment **

whenever --update-crontab --set environment='development'

Put in Capistrano


set :whenever_roles, -> { :app }


require 'whenever/capistrano'

Solving addiction

Doesn't work on EC2

After deploying to EC2, crontab does not work, and when I check the log, the Bundle version is incorrect.

Job_type should be set to


set :output, environment == 'development' ? 'log/crontab.log' : '/deploy/apps/<app name/shared/log/crontab.log'
job_type :rake, 'export PATH="$HOME/.rbenv/bin:$PATH"; eval "$(rbenv init -)"; cd :path && RAILS_ENV=:environment bundle exec rake :task :output'

Doesn't work on time

The time zone is likely to be wrong.

How to set the time zone:


require 'active_support/core_ext/time'

def local(time)
  Time.zone = 'Asia/Tokyo'

every 1.day, at: local('6:00 am') do #Runs every morning at 6am Japan time
  rake '<task>'

When you get an ExecJS :: RuntimeUnavailable error in the crontab log

Could not find a JavaScript runtime. See https://github.com/rails/execjs for a list of available runtimes. (ExecJS::RuntimeUnavailable)

Just add mini_racer to your Gemfile. therubyracer is fine, but it's difficult to install on Mac, so use mini_racer.

Recommended Posts

[Ruby on Rails] Solving the addiction when setting crontab using whenever in EC2
When the Ruby on Rails terminal rolls back
[Ruby on Rails] When logging in for the first time ・ How to split the screen in half using jQuery
[Ruby on Rails Tutorial] Error in the test in Chapter 3
Try using the query attribute of Ruby on Rails
Ruby on Rails Email automatic sending function setting (using gmail)
[Ruby on Rails] Quickly display the page title in the browser
Ruby on Rails Japanese-English support i18n
I summarized the flow until implementing simple_calendar in Ruby on Rails.
Things to remember and concepts in the Ruby on Rails tutorial
When using Slim in Ruby on Rails, "undefined local variable or method` f'for "is displayed in form_with
[Ruby on Rails] How to log in with only your name and password using the gem devise
[Ruby on Rails] Code check using Rubocop-airbnb
How to create a query using variables in GraphQL [Using Ruby on Rails]
[Ruby On Rails] In the create action and destroy action, emergency measures when redirect_to action:: show cannot be (cannot be used)
part of the syntax of ruby ​​on rails
"" Application.js "is not present in the asset pipeline" error in Ruby on Rails
Ruby on Rails in Visual Studio Codespaces
What to do when Blocked Host: "host name" appears in Ruby on Rails
Notes on using FCM with Ruby on Rails
[Ruby on Rails] Image slideshow using Skippr
How to debug the processing in the Ruby on Rails model only on the console
Cloud IDE: Heroku couldn't be installed in the Ruby on Rails tutorial
Beginners create portfolio in Ruby on Rails
Ruby on Rails When you don't know the cause of rollback when saving.
[Ruby On Rails] How to search the contents of params using include?
How to resolve errors that occur in the "Ruby on Rails" integration test
How to implement image posting function using Active Storage in Ruby on Rails
[Ruby On Rails] Error in test using RSpec MySQL client is not connected
[Ruby on Rails] Until the introduction of RSpec
Recommendation of Service class in Ruby on Rails
Publish the app made with ruby on rails
Rails new in Ruby on Rails ~ Memorandum until deployment 2
Rails new in Ruby on Rails ~ Memorandum until deployment 1
(Ruby on Rails6) Creating data in a table
Determine the current page with Ruby on Rails
[Ruby on Rails] How to install Bootstrap in Rails
[Ruby on Rails] Implementation of validation that works only when the conditions are met
Ruby on Rails Incorrect string value error resolution when posting a form in Japanese
[Ruby On Rails] In the nested state, the description in parentheses written after Prefix in the link_to method
[Ruby on rails] When executing the heroku command, bash: heroku: command not found is displayed. [Rails tutorial]
[Ruby on Rails] How to write enum in Japanese
Docker the development environment of Ruby on Rails project
Examine the elements in the array using the [Ruby] includes? Method
[Ruby on Rails] How to change the column name
Regarding overcapacity when setting Rails tutorial environment in Cloud 9
[Ruby On Rails] How to reset DB in Heroku
[Ruby / Rails] Set a unique (unique) value in the class
[Ruby on Rails] Common processing between controllers (using concaves)
[Ruby on Rails] Post image preview function in refile
Solve the N + 1 problem with Ruby on Rails: acts-as-taggable-on
Ruby on Rails environment construction using VirtualBox, Vagrant, cyberduck
Ruby on Rails Tutorial Troublesome notes when running on Windows
(Ruby on Rails6) Reflecting the posted content from the form
Differences in code when using the length system in Java
Ruby on Rails 5 quick learning practice guide that can be used in the field Summary
[Ruby] Get in the habit of using the dup method when making a copy of a string variable
[Ruby on Rails] I want to get the URL of the image saved in Active Storage
[Ruby On Rails] How to update the calculated result to an integer type column using update_column
What to do when Rails on Docker does not reflect controller changes in the browser
Launch Rails on EC2