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

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.

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