How to get a rake task to run in a development environment using a gem ever

I use When when gem to complete the rake task. When I run the rake task, it starts in the development environment, but when it starts at the scheduled time, it refers to the production environment. How can I get a scheduled rake command to run in a development environment. As far as I understand, I have to use the variable RAILS_ENV, but I can not figure out where to put it. I think this has nothing to do with wherever the stone is.

+6
source share
2 answers

In schedule.rb you can specify the environment in which you plan to run scheduled tasks:

 # config/schedule.rb set :environment, 'development' 

Alternatively, you can configure the environment for each job:

 # config/schedule.rb every 1.day do runner 'Model.task', :environment => 'development' runner 'Model.task', :environment => 'production' end 
+6
source

In any bash -type bash , you can usually override the environment when it starts:

 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... 

It can be adapted for other shells as needed.

+12
source

Source: https://habr.com/ru/post/948289/


All Articles