Rake only works once from rails

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,

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).

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.