# Rake only works once from rails

**URL:** <https://www.ruby-forum.com/t/rake-only-works-once-from-rails/133044>\
**Category:** Ruby\
**Created:** [March 27, 2008, 12:57am UTC](https://www.ruby-forum.com/t/rake-only-works-once-from-rails/133044 "2008-03-27T00:57:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ddancer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ecb155/32.png) [@ddancer](https://www.ruby-forum.com/u/ddancer)\
**Post date:** [March 27, 2008, 12:57am UTC](https://www.ruby-forum.com/t/rake-only-works-once-from-rails/133044/1 "2008-03-27T00:57:12Z")

</div>

sorry this is rails related, but I think it’s more of a Rake thing

I’ve made a rake task that I’m running from my rails, and it works - but  
only once. If I then restart the server (mongrel) it works again -  
once.

I can simulate this in the console session as shown…

q = Rake::Task[“cache\_sweeper”]  
=\> \<Rake::Task cache\_sweeper =\> []\>

> > q.invoke  
> > =\>  
> > [#Proc:0xb6d03444@./script/../config/../config/../lib/tasks/cache.rake:4]
> 
> > q = Rake::Task[“cache\_sweeper”]  
> > =\> \<Rake::Task cache\_sweeper =\> []\>
> 
> > q.invoke  
> > =\> nil
> 
> >

… when q.invoke returns the “[#Proc:…” it has worked correctly, nil  
means nothing happened.

Any one have insight to what is happening with rake?

Thank you,

---

<div class="post-metadata">

**Author:** ![ddancer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ecb155/32.png) [@ddancer](https://www.ruby-forum.com/u/ddancer)\
**Post date:** [March 28, 2008, 12:58am UTC](https://www.ruby-forum.com/t/rake-only-works-once-from-rails/133044/2 "2008-03-28T00:58:02Z")

</div>

On Mar 26, 2008, at 16:55 , Andy K. wrote:

> cache.rake:4\>]  
> Any one have insight to what is happening with rake?  
> It is doing it’s job. Rake runs tasks once by definition. It is a  
> build tool. That is what it is for.

---

<div class="post-metadata">

**Author:** ![ddancer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ecb155/32.png) [@ddancer](https://www.ruby-forum.com/u/ddancer)\
**Post date:** [March 28, 2008, 7:27pm UTC](https://www.ruby-forum.com/t/rake-only-works-once-from-rails/133044/3 "2008-03-28T19:27:35Z")

</div>

Ryan D. wrote:

> > > > q.invoke  
> > > > … when q.invoke returns the “[#Proc:…” it has worked correctly,  
> > > > nil means nothing happened.
> > 
> > Any one have insight to what is happening with rake?
> 
> It is doing it’s job. Rake runs tasks once by definition. It is a build  
> tool. That is what it is for.

ah, so my usage is incorrect - that’s what I was suspecting

Thanks for confirming my suspicions

---

<div class="post-metadata">

**Author:** ![ddancer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ecb155/32.png) [@ddancer](https://www.ruby-forum.com/u/ddancer)\
**Post date:** [March 28, 2008, 10:10pm UTC](https://www.ruby-forum.com/t/rake-only-works-once-from-rails/133044/4 "2008-03-28T22:10:18Z")

</div>

On Mar 28, 2008, at 11:26 , Andy K. wrote:

> ah, so my usage is incorrect - that’s what I was suspecting
> 
> Thanks for confirming my suspicions

just change task to def and remove the do and you should be fine. keep  
rake required to cheat and get fileutils and other handy utility  
methods added.
