Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to force rake task to run under development environment using Whenever gem

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.

like image 712
Askar Avatar asked Jun 28 '13 05:06

Askar


2 Answers

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.

like image 157
tadman Avatar answered Sep 23 '22 18:09

tadman


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 
like image 27
zeantsoi Avatar answered Sep 23 '22 18:09

zeantsoi