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

Askar picture Askar · Jun 28, 2013 · Viewed 7.3k times · Source

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.

Answer

tadman picture tadman · Jun 28, 2013

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.