views:

90

answers:

1

I have a BackgrounDRb worker set up to run its 'sync' method every 15 minutes. Then, say, I want to run the method once just now. I was trying to wrap that in a rake task as follows:

namespace :mytasks do
  task :sync do |t|
    worker = MiddleMan.worker(:my_worker)
    worker.async_sync
  end
end

But this doesn't work. It bails out with all sorts of undefined constants and so on. None of my tries to require misc. gems produced a runnable rake task. :(

So, the question is how do you trigger a BackgrounDRb task from within a rake task?

+1  A: 

I'm not sure about the particulars of running BackroundDRb-tasks, but if you want to incude the rails environment in your rake task, you have to be explicit about it. I'm pretty sure the lack of this is what causes your rake task to fail.

namespace :foo do
  task :bar => :environment do |t|
    # ..
  end
end
August Lilleaas