On our staging server we run our Rails application in the production environment so as to be as similar as possible to our production server. We're using whenever to create our crontab. However, we need to run a slightly different rake task for our sitemap generation so it doesn't ping Google and Bing.
In deploy.rb, we have:
set :stages, %w(production staging)
, but in both deploy/staging.rb and deploy/production.rb we have :rails_env, "production"
set, so I can't use Rails.env
.
In schedule.rb
, I want to do something like:
every :day, at: '1am' do
if @stage == 'production'
rake 'sitemap:refresh'
else
rake 'sitemap:refresh:no_ping'
end
end
How can I make that variable available?
Update
I was able to solve it by putting
set :whenever_variables, defer { "stage=#{stage}" }
into my deploy/staging.rb. I then had access to @stage
in schedule.rb