如何使用sidekiq-scheduler每30秒安排一次

时间:2016-07-27 10:21:21

标签: ruby-on-rails scheduler sidekiq ruby-on-rails-4.1

我正在研究ROR申请。 我有一个功能要求,我必须为其调用方法 每30秒使用sidekiq

我正在使用这些宝石

# sidekiq
gem 'sidekiq', '~> 3.3.0'
# sidekiq scheduler
gem 'sidekiq-scheduler', '~> 2.0'

这是我的scheduler.yml文件代码。

perform:
  every: ["30s"]
  class: Aggregator
  queue: aggregation
  description: "This job will create Aggregate data."

这是我的Aggregator类,它位于Workers文件夹中。

class Aggregator
  include Sidekiq::Worker
  sidekiq_options :backtrace => 5, :retry => false

  def perform
    end_time = time - (time.sec%30).seconds
    puts "ROUNDING TO 30 SEC"
    puts end_time    
   Session.create_aggregate_data(end_time)
  end
end

当我检查sidekiq日志时,它没有按下执行方法。但是聚合器类被称为

这是日志..

2016-07-27T10:19:59.436Z 15117 TID-1qjnlu INFO: queueing Aggregator (perform)
2016-07-27T10:20:29.641Z 15117 TID-1qjnlu INFO: queueing Aggregator (perform)
2016-07-27T10:20:59.836Z 15117 TID-1qjnlu INFO: queueing Aggregator (perform)
2016-07-27T10:21:30.009Z 15117 TID-1qjnlu INFO: queueing Aggregator (perform)
2016-07-27T10:22:00.204Z 15117 TID-1qjnlu INFO: queueing Aggregator (perform)
2016-07-27T10:22:30.507Z 15117 TID-1qjnlu INFO: queueing Aggregator (perform)
2016-07-27T10:23:00.509Z 15117 TID-1qjnlu INFO: queueing Aggregator (perform)
2016-07-27T10:23:30.760Z 15117 TID-1qjnlu INFO: queueing Aggregator (perform)
2016-07-27T10:24:01.068Z 15117 TID-1qjnlu INFO: queueing Aggregator (perform)

1 个答案:

答案 0 :(得分:0)

如果您没有配置非默认队列

,请尝试将队列设置为默认值
queue: default