Rufus调度程序与独角兽一起运行多次,并通过:lockfile修复,但是如何消除错误味精? [英] Rufus scheduler running multiple times with unicorn, fixed with :lockfile, but how to eliminate the error msg?

查看:142
本文介绍了Rufus调度程序与独角兽一起运行多次,并通过:lockfile修复,但是如何消除错误味精?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

scheduler = Rufus::Scheduler.new :lockfile => ".rufus-scheduler.lock"

scheduler.every("60") do
...
end

环境:Ubuntu,rails 4,rufus,独角兽,nginx

Environment: Ubuntu, rails 4, rufus, unicorn, nginx

独角兽有多个工作人员,因此上述每一项"任务将每60秒执行多次.

Unicorn has multiple workers, so the above 'every' task will be executed multiple times every 60 seconds.

根据这一答案: rufus调度程序每次运行两次 ,我添加了:lockfile选项,它有效!

According to the answer for this one: rufus scheduler running twice each time , I added :lockfile option, and it works!

但是,从日志来看,似乎每个"任务仍然试图被调用,从而导致出现许多错误消息:

However, from the log, it seems that the 'every' task still tries to be called, resulting in a lot of error messages:

E, [2014-05-09T01:59:47.496840 #2747] ERROR -- : cannot schedule, scheduler is down or shutting down (Rufus::Scheduler::NotRunningError)
/home/sohmobile/shared/bundle/ruby/2.1.0/gems/rufus-scheduler-3.0.7/lib/rufus/scheduler.rb:605:in `do_schedule'
/home/sohmobile/shared/bundle/ruby/2.1.0/gems/rufus-scheduler-3.0.7/lib/rufus/scheduler.rb:209:in `every'
/home/sohmobile/releases/20140509014407/config/initializers/task_scheduler.rb:3:in `<top (required)>'

我该如何解决这个问题?

How can I solve this issue?

谢谢.

推荐答案

这可以解决您的问题:

require 'rufus-scheduler'

scheduler = Rufus::Scheduler.new(:lockfile => ".rufus-scheduler.lock")

unless scheduler.down?

  scheduler.every("60") do
    # ...
  end
end

这篇关于Rufus调度程序与独角兽一起运行多次,并通过:lockfile修复,但是如何消除错误味精?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆