문제

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.

도움이 되었습니까?

해결책 2

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 

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top