invoking a rake task inside a rufus-scheduler
I am trying to run a rake task inside a scheduler l开发者_高级运维ike below
scheduler = Rufus::Scheduler.new
scheduler.start
schedule.schedule(chron) do
puts "in scheduler"
begin
ENV['RAILS_ENV']='production'
Rake::Task['connection'].invoke
rescue Exception => e
puts "error"
end
the rake task is executed only for the first time. but the scheduler seem to be running in the given interval.
Any help appreciated.
Rake is a dependency processor. It runs a task only once unless you tell it otherwise. See http://rake.rubyforge.org/classes/Rake/Task.html#M000115 You need to
def force_invoke(task)
task.reenable
task.invoke
end
精彩评论