Andrey Subbotin
Andrey Subbotin

Reputation: 5373

How do I code a rake task to trigger a BackgrounDRb task?

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?

Upvotes: 1

Views: 287

Answers (1)

August Lilleaas
August Lilleaas

Reputation: 54603

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

Upvotes: 1

Related Questions