【问题标题】:Error "undefined method `to_datetime'" in sidekiqsidekiq 中的错误“未定义方法 `to_datetime'”
【发布时间】:2017-12-02 22:12:17
【问题描述】:

用命令启动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 &lt;=&gt;时出错:

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

【问题讨论】:

    标签: ruby-on-rails ruby ruby-on-rails-3 cron sidekiq


    【解决方案1】:

    您的问题不是来自 sidekiq,而是来自 Rails 3.2.13。 #&lt;=&gt; 不处理 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 版本。如果不是选项,请粘贴您的代码或重写#&lt;=&gt;

    【讨论】:

    • 谢谢,现在comparison of Time with EtOrbi::EoTime failed
    【解决方案2】:

    to_datetime 是 rails 的 activesupport library 中的一种方法,而您的 sidekiq 工作人员没有使用它。

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

    【讨论】:

    • 似乎比较失败了,因为您试图将 gem EtOrbi::EoTime 中的时间对象与 ruby​​ 的标准 DateTime 对象进行比较
    • 老实说,我不会调试 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-30
    • 1970-01-01
    • 2016-08-18
    相关资源
    最近更新 更多