在rufus-scheduler中调用rake任务

时间:2010-11-27 18:00:46

标签: ruby-on-rails scheduled-tasks

我正在尝试在下面的调度程序中运行rake任务

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

rake任务仅在第一次执行。但调度程序似乎在给定的时间间隔内运行。

任何帮助表示感谢。

1 个答案:

答案 0 :(得分:2)

Rake是一个依赖处理器。它只运行一次任务,除非你另有说明。请参阅http://rake.rubyforge.org/classes/Rake/Task.html#M000115您需要

def force_invoke(task)
  task.reenable
  task.invoke
end