rufus-scheduler由于独角兽工作者而多次运行调度程序 [英] rufus-scheduler runs scheduler multiple times due to unicorn workers

查看:111
本文介绍了rufus-scheduler由于独角兽工作者而多次运行调度程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在rails3项目的/configs/initializers/schedule.rb中安装了设置调度程序,并且工作正常,但是它工作了2次,我认为这是由于独角兽工人同时执行调度程序,所以它在我的系统中创建数据库每次有两个记录. 我检查了逻辑及其确定,然后在本地计算机中输入了一条记录.

I had setup scheduler in my rails3 projects's /configs/initializers/schedule.rb and it working fine, But it works 2 times and I think it is due to unicorn workers execute schedule at the same time, so it create in my database two records each time. I checked my logic and its ok and enter single record in my local machine.

我检查了以下内容,但不知道如何阻止多个独角兽工作者执行调度程序?

I checked following but not getting idea how to stop multiple unicorn workers to execute scheduler?

https://github.com/jmettraux/rufus-scheduler/#高级锁定方案

有人遇到这个问题吗?请帮忙.

Any one got this issue? Please help if any idea.

谢谢

P Shah

推荐答案

尝试一下

require 'rufus-scheduler'

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

unless scheduler.down?

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

这篇关于rufus-scheduler由于独角兽工作者而多次运行调度程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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