在sidekiq中出错“undefined method`to_datetime'”

时间:2017-06-29 09:26:44

标签: ruby-on-rails ruby ruby-on-rails-3 cron 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:更新版本导轨至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

2 个答案:

答案 0 :(得分:1)

您的问题不是来自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版本。如果不是选项粘贴您的代码或重写#<=>

答案 1 :(得分:1)

to_datetime是rails'activesupport library的一种方法,而你的sidekiq工作者没有使用它。

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