sidekiq 中的错误 "undefined method `to_datetime'"

Error "undefined method `to_datetime'" in sidekiq

使用命令启动sidekiq

bundle exec sidekiq -e production -P /path/to/pid/file/tmp/pids/sidekiq.pid -L /path/to/log/file/shared/log/sidekiq.log --daemon

在日志错误

2017-06-29T06:59:44.776Z 16181 TID-1jr7pg ERROR: CRON JOB: undefined method `to_datetime' for #<EtOrbi::EoTime:0x0000000a933848>
2017-06-29T06:59:44.776Z 16181 TID-1jr7pg ERROR: CRON JOB: /home/user/.rvm/gems/ruby-2.0.0-p247@script-admin/gems/activesupport-3.2.13/lib/active_support/core_ext/date_time/calculations.rb:141:in `<=>'

执行方法时出错 /home/user/.rvm/gems/ruby-2.0.0-p247@script-admin/gems/activesupport-3.2.13/lib/active_support/core_ext/date_time/calculations.rb:141:in <=>:

def <=> (other)
  super other.kind_of?(Infinity) ? other : other.to_datetime
end

遇到问题可以做什么?


UPD: 更新版本 rails 到 3.2.22.5 并且有一个新错误

ERROR: CRON JOB: comparison of Time with EtOrbi::EoTime failed
ERROR: CRON JOB: /home/user/.rvm/gems/ruby-2.0.0-p247@script-admin/gems/sidekiq-cron-0.3.1/lib/sidekiq/cron/job.rb:434:in `<'

在这个地方

def not_enqueued_after?(time)
  @last_enqueue_time.nil? || @last_enqueue_time < last_time(time)
end

您的问题不是来自 sidekiq,而是来自 Rails 3.2.13。 #<=> 不处理 undefined method to_datetime。它在 Rails 的未来版本中得到修复。例如,在 Rails 3.2.22.5:

def <=>(other)
  if other.kind_of?(Infinity)
    super
  elsif other.respond_to? :to_datetime
    super other.to_datetime
  else
    nil
  end
end

因此,解决您的问题的最简单方法是更新您的 Rails 版本。如果不是选项,请粘贴您的代码或重写 #<=>.

to_datetime 是 rails' activesupport library 中的一种方法,您的 sidekiq worker 没有使用它。

尝试将 require 'active_support/core_ext' 添加到您的 sidekiq 初始化程序配置 config/initializers/sidekiq.rb 并重新启动 sidekiq