# Rake only works once from rails

**URL:** <https://www.ruby-forum.com/t/rake-only-works-once-from-rails/133105>\
**Category:** Rails\
**Created:** [March 27, 2008, 7:45pm UTC](https://www.ruby-forum.com/t/rake-only-works-once-from-rails/133105 "2008-03-27T19:45:47Z")\
**Posts on this page:** 3\
**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, 7:45pm UTC](https://www.ruby-forum.com/t/rake-only-works-once-from-rails/133105/1 "2008-03-27T19:45:47Z")

</div>

posted this on Ruby forum, no luck there -

maybe a Railser has dealt with this issue…

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 27, 2008, 7:51pm UTC](https://www.ruby-forum.com/t/rake-only-works-once-from-rails/133105/2 "2008-03-27T19:51:48Z")

</div>

I was having this problem just last night with a migration. I don’t  
know why it happens, but I can tell you how I got around it: I changed  
the iteration number of the migration file itself. In other words, I  
had a file called 001\_create\_schedules.rb; I renamed the file to  
002\_create\_schedules.rb.

I guess that is more of a workaround than a solution, but it might keep  
you running in the meantime until you can get a more in-depth response  
here in the forum (I’m a newbie too).

---

<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, 8:01pm UTC](https://www.ruby-forum.com/t/rake-only-works-once-from-rails/133105/3 "2008-03-27T20:01:14Z")

</div>

that sounds like your schema table had indexed to 1, which would mean it  
won’t run the “001\_xxx” migration again

unless you rollback to version 0, or manually change the schema table  
value to 0

I’ve embedded a call to a rake task with a controller action, this rake  
task only runs the first time it is called.
