Cron参数在sidekiq rails中不起作用

时间:2016-12-01 14:12:38

标签: ruby-on-rails redis sidekiq sidetiq

我在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 `-'

如何解决此问题?

0 个答案:

没有答案