2

我已经在我的 rails 应用程序中实现了 sidekiq-cron 。我想使用这个 gem 运行计划任务。

这是 yml 文件 config/schedule.yml :

message_worker:
  class: MessageWorker
  queue: default
  cron: "* * * * * *"

这是我的工人阶级:

class MessageWorker
  include Sidekiq::Worker
  sidekiq_options retry: 2, backtrace: true
  def perform()
    # Here is my business logic
  end
end

在这里,我将所有任务加载到初始化文件中:

require 'sidekiq'
require 'sidekiq-cron'
require 'sidekiq/web'

redis_config = YAML.load_file("config/redis.yml")
redis_config.merge! redis_config.fetch(Rails.env, {})
redis_config.symbolize_keys!

Sidekiq.configure_server do |config|
  config.redis = { url: "redis://localhost:6379/" }
  puts "redis started"
end

Sidekiq.configure_client do |config|
  config.redis = { url: "redis://localhost:6379/" }
  puts "configure client"
end
schedule_file = "config/schedule.yml"

if File.exists?(schedule_file) && Sidekiq.server?
 sidekiq_cron = YAML.load_file(schedule_file)
 Sidekiq::Cron::Job.load_from_hash sidekiq_cron
end

当我使用 bundle ex sedikiq 运行 sidekiq 服务器时,它会抛出以下异常:

2016-12-01T14:08:36.916Z 12150 TID-orgj0i010 ERROR: CRON JOB: can't convert Rufus::Scheduler::ZoTime into an exact number
2016-12-01T14:08:36.916Z 12150 TID-orgj0i010 ERROR: CRON JOB: /home/user/.rvm/gems/ruby-2.3.0@<gemset-name>/gems/activesupport-4.2.7.1/lib/active_support/core_ext/time/calculations.rb:233:in `-'

我该如何解决这个问题?

4

0 回答 0