新手问题 那位大侠用过 Sidekiq?

topswim · 2013年11月25日 · 最后由 neverlandxy_naix 回复于 2013年11月26日 · 4453 次阅读

我的类如下:

class GetDataWorker
  # To change this template use File | Settings | File Templates.
  include Sidekiq::Worker
  include Sidetiq::Schedulable

  recurrence { minutely(15) }

  def perform
    # do stuff ...
    puts "#{Time.now}"
    CicsasNum.new.get_cicsas_num
    InformixDbsSpace.new.get_db_space
  end
end

执行命令后提示:

 bundle exec sidekiq
/Users/liucc/.rvm/gems/ruby-1.9.2-p320/gems/actionpack-3.2.12/lib/action_dispatch/http/mime_type.rb:102: warning: already initialized constant PDF
undefined method `recurrence' for GetDataWorker:Class
/Users/liucc/omm/app/workers/get_data_worker.rb:6:in `<class:GetDataWorker>'

recurrence 这个方法怎么找不到啊?

准备换这个试试。。

准备研究 Sidetiq 的路过~~

upgrade ur sidekiq

#4 楼 @helloword 谢谢! 但是这个又是怎么回事?

2013-11-25T11:02:56Z 10709 TID-owqr984b4 INFO: [Sidetiq] Sidetiq v0.4.3 - Copyright (c) 2012-2013, Tobias Svensson <[email protected]>
2013-11-25T11:02:56Z 10709 TID-owqr984b4 INFO: [Sidetiq] Sidetiq is covered by the 3-clause BSD license.
2013-11-25T11:02:56Z 10709 TID-owqr984b4 INFO: [Sidetiq] See LICENSE and http://opensource.org/licenses/BSD-3-Clause for licensing details.
2013-11-25T11:02:56Z 10709 TID-owqr984b4 INFO: [Sidetiq] Sidetiq::Supervisor start
2013-11-25T11:02:56Z 10709 TID-owqrotyb8 INFO: [Sidetiq] Sidetiq::Actor::Clock id: 70272553391540 initialize
2013-11-25T11:02:56Z 10709 TID-owqrvjc8g INFO: [Sidetiq] Sidetiq::Actor::Handler id: 70272572944420 initialize
2013-11-25T11:02:56Z 10709 TID-owqrvgpfo INFO: [Sidetiq] Sidetiq::Actor::Handler id: 70272572807740 initialize
2013-11-25T11:02:56Z 10709 TID-owqrvgdbk INFO: [Sidetiq] Sidetiq::Actor::Handler id: 70272572794800 initialize
2013-11-25T11:02:56Z 10709 TID-owqrvfxi4 INFO: [Sidetiq] Sidetiq::Actor::Handler id: 70272572771580 initialize
2013-11-25T11:02:56Z 10709 TID-owqrotyb8 WARN: [Sidetiq] Can't link Sidetiq::Actor::Clock. Sidekiq::Manager not running. Retrying in 5 seconds ...
2013-11-25T11:02:56Z 10709 TID-owqrvjc8g WARN: [Sidetiq] Can't link Sidetiq::Actor::Handler. Sidekiq::Manager not running. Retrying in 5 seconds ...
2013-11-25T11:02:56Z 10709 TID-owqrvgpfo WARN: [Sidetiq] Can't link Sidetiq::Actor::Handler. Sidekiq::Manager not running. Retrying in 5 seconds ...
2013-11-25T11:02:56Z 10709 TID-owqrvgdbk WARN: [Sidetiq] Can't link Sidetiq::Actor::Handler. Sidekiq::Manager not running. Retrying in 5 seconds ...
2013-11-25T11:02:56Z 10709 TID-owqrvfxi4 WARN: [Sidetiq] Can't link Sidetiq::Actor::Handler. Sidekiq::Manager not running. Retrying in 5 seconds ...
/Users/liucc/.rvm/gems/ruby-1.9.2-p320/gems/actionpack-3.2.12/lib/action_dispatch/http/mime_type.rb:102: warning: already initialized constant PDF
2013-11-25T11:02:59Z 10709 TID-owqr984b4 INFO: Booting Sidekiq 2.15.2 using redis://localhost:6379/0 with options {}
2013-11-25T11:02:59Z 10709 TID-owqr984b4 INFO: Running in ruby 1.9.2p320 (2012-04-20 revision 35421) [x86_64-darwin12.2.0]
2013-11-25T11:02:59Z 10709 TID-owqr984b4 INFO: See LICENSE and the LGPL-3.0 for licensing details.
2013-11-25T11:02:59Z 10709 TID-owqr984b4 INFO: Starting processing, hit Ctrl-C to stop
2013-11-25T11:03:24Z 10709 TID-owqrz8xf0 WARN: Sidekiq died due to the following error, cannot recover, process exiting
2013-11-25T11:03:24Z 10709 TID-owqrz8xf0 WARN: linking timeout of 5 seconds exceeded
2013-11-25T11:03:24Z 10709 TID-owqrz8xf0 WARN: /Users/liucc/.rvm/gems/ruby-1.9.2-p320/gems/celluloid-0.15.2/lib/celluloid/actor.rb:217:in `block (2 levels) in linking_request'
/Users/liucc/.rvm/gems/ruby-1.9.2-p320/gems/celluloid-0.15.2/lib/celluloid/actor.rb:203:in `loop'
/Users/liucc/.rvm/gems/ruby-1.9.2-p320/gems/celluloid-0.15.2/lib/celluloid/actor.rb:203:in `block in linking_request'
/Users/liucc/.rvm/gems/ruby-1.9.2-p320/gems/celluloid-0.15.2/lib/celluloid/tasks.rb:109:in `exclusive'
/Users/liucc/.rvm/gems/ruby-1.9.2-p320/gems/celluloid-0.15.2/lib/celluloid.rb:431:in `exclusive'
/Users/liucc/.rvm/gems/ruby-1.9.2-p320/gems/celluloid-0.15.2/lib/celluloid/actor.rb:198:in `linking_request'
/Users/liucc/.rvm/gems/ruby-1.9.2-p320/gems/celluloid-0.15.2/lib/celluloid/actor.rb:90:in `monitor'
/Users/liucc/.rvm/gems/ruby-1.9.2-p320/gems/celluloid-0.15.2/lib/celluloid/actor.rb:101:in `link'
/Users/liucc/.rvm/gems/ruby-1.9.2-p320/gems/celluloid-0.15.2/lib/celluloid.rb:383:in `link'
/Users/liucc/.rvm/gems/ruby-1.9.2-p320/gems/celluloid-0.15.2/lib/celluloid/calls.rb:25:in `public_send'
/Users/liucc/.rvm/gems/ruby-1.9.2-p320/gems/celluloid-0.15.2/lib/celluloid/calls.rb:25:in `dispatch'
/Users/liucc/.rvm/gems/ruby-1.9.2-p320/gems/celluloid-0.15.2/lib/celluloid/calls.rb:67:in `dispatch'
/Users/liucc/.rvm/gems/ruby-1.9.2-p320/gems/celluloid-0.15.2/lib/celluloid/actor.rb:322:in `block in handle_message'
/Users/liucc/.rvm/gems/ruby-1.9.2-p320/gems/celluloid-0.15.2/lib/celluloid/actor.rb:416:in `block in task'
/Users/liucc/.rvm/gems/ruby-1.9.2-p320/gems/celluloid-0.15.2/lib/celluloid/tasks.rb:55:in `block in initialize'
/Users/liucc/.rvm/gems/ruby-1.9.2-p320/gems/celluloid-0.15.2/lib/celluloid/tasks/task_fiber.rb:13:in `block in create'
2013-11-25T11:03:25Z 10709 TID-owqrvjc8g INFO: [Sidetiq] Sidetiq::Actor::Handler id: 70272572944420 shutting down ...

这两天 google 都上不去,没地方搜啊

#6 楼 @topswim perform 里面的任务换成最简单的试试呢?比如就要puts "#{Time.now}" 这行。。 我今晚刚切换到这个上来,没有出现问题,除了你的这个坑,还好你帮我踩了,哈哈

#7 楼 @small_fish__ 换成最简单可以,但是加上我调用的类就不行了!

#7 楼 @small_fish__ 发个你的 JOB 让我看看。

#9 楼 @topswim 我的 Schedulable jobs 也写的简单的测试,不过一般的 works 还是成功的啊。。

#10 楼 @small_fish__ 哦!我再看看!

#10 楼 @small_fish__ 我发现我把频率设置成 1 分钟没有报错,但是设置成 10 分钟就报错退出。不知道你有没有这种现象?

recurrence 是 sidetiq 里的,不是 sidekiq 的

#12 楼 @topswim 暂时没有遇到这样的问题

#14 楼 @small_fish__ 我发现是 recurrence 写法的问题,我用 ice_cube 写法就会有问题。 只能这样写 recurrence { hourly.minute_of_hour(0, 15, 30, 45) } 不能这样写 recurrence { minutely(15) } 因为:Unfortunately, using ice_cube's interval methods is terribly slow on start-up (it tends to eat up 100% CPU for quite a while) and on every recurrence run. This is due to it calculating every possible occurrence since the schedule's start time. The way around is to avoid using them.

#15 楼 @topswim 原来如此,我昨晚上本来想说这个的,但是看到官网也有你这种写法,就没提了,btw: 我昨晚上的测试用的是 recurrence { minutely.second_of_minute(0, 15, 30, 45) }

😄 谢谢,以后还是老大老实的用这种写法了。。

好好看文档啊,sidekiq 的文档写的很好的,什么都说明白了。

需要 登录 后方可回复, 如果你还没有账号请 注册新账号