Вопрос

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