I have been implemented sidekiq-cron in my rails application. I want to run scheduled task using this gem.
Here is yml file config/schedule.yml :
message_worker:
class: MessageWorker
queue: default
cron: "* * * * * *"
Here is my worker class:
class MessageWorker
include Sidekiq::Worker
sidekiq_options retry: 2, backtrace: true
def perform()
# Here is my business logic
end
end
Here I loading all my task in initializer file:
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
When I run sidekiq server using bundle ex sedikiq it throws me below exception:
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 `-'
How Can I resolve this problem?