I'm using Whenever gem to run a rake task. When I run rake task it runs under development environment, but when it runs on a scheduled time it refers to a production environment. How can I force to run a scheduled rake task under development environment. As I understand I'll have to use RAILS_ENV variable, but can't figure out where to put it. I think, it has nothing to do with Whenever gem here.
In any bash
-type shell you can usually override the environment when you run it:
RAILS_ENV=development rake task:name...
You can also write a small script to do this for you:
#!/bin/sh
export RAILS_ENV=development
rake task:name...
This can be adapted for other shells as required.
In schedule.rb
, you can specify the environment you'd like scheduled tasks to be run in:
# config/schedule.rb
set :environment, 'development'
Alternatively, you can set the environment on a per-job basis:
# config/schedule.rb
every 1.day do
runner 'Model.task', :environment => 'development'
runner 'Model.task', :environment => 'production'
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With