# Can rails environments be loaded only once and then execute rake tasks without loading it again an

**URL:** <https://www.ruby-forum.com/t/can-rails-environments-be-loaded-only-once-and-then-execute-rake-tasks-without-loading-it-again-an/166418>\
**Category:** Rails\
**Created:** [April 24, 2009, 11:16pm UTC](https://www.ruby-forum.com/t/can-rails-environments-be-loaded-only-once-and-then-execute-rake-tasks-without-loading-it-again-an/166418 "2009-04-24T23:16:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Canvas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b487fb/32.png) [@Canvas](https://www.ruby-forum.com/u/Canvas)\
**Post date:** [April 24, 2009, 11:16pm UTC](https://www.ruby-forum.com/t/can-rails-environments-be-loaded-only-once-and-then-execute-rake-tasks-without-loading-it-again-an/166418/1 "2009-04-24T23:16:59Z")

</div>

Hi there guys,

I have a daemon that executes a rake task periodically in a loop in  
the backend. And every time it runs the rake task, rails environment  
is reloaded. Is there a way that the rails environment is loaded only  
once before the loop and the following rake task will not load it  
again and again?

Thank you in advance.

---

<div class="post-metadata">

**Author:** ![Canvas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b487fb/32.png) [@Canvas](https://www.ruby-forum.com/u/Canvas)\
**Post date:** [May 2, 2009, 8:10am UTC](https://www.ruby-forum.com/t/can-rails-environments-be-loaded-only-once-and-then-execute-rake-tasks-without-loading-it-again-an/166418/2 "2009-05-02T08:10:52Z")

</div>

Canvas wrote:

> I have a daemon that executes a rake task periodically in a loop in  
> the backend. And every time it runs the rake task, rails environment  
> is reloaded. Is there a way that the rails environment is loaded only  
> once before the loop and the following rake task will not load it  
> again and again?

rake tasks are only for user-programmers to enter into command lines.  
(Like  
‘make’ in legacy programming. You wouldn’t make over and over again on a  
server!) rake tasks are for things like migrating the DB or running your  
tests. (And yes it would be nice for them to run faster!)

You need to configure your daemon to simply run script/runner  
my\_script.rb.  
That invokes the correct environment, and generally builds a miniature  
Rails  
machine that models and (I suspect) controllers can run in.

However, if you actually do correlate file times with tasks (the root  
principle of \*ake technology), then you either need to express that  
correlation explicitely, or use a rake task to do it!

–  
Phlip
