lib/delayed_cron/jobs/sidekiq.rb in delayed_cron-0.2.6 vs lib/delayed_cron/jobs/sidekiq.rb in delayed_cron-0.2.7

- old
+ new

@@ -6,41 +6,51 @@ class Sidekiq include ::Sidekiq::Worker sidekiq_options :queue => :cron_job def self.enqueue_delayed_cron(klass, method_name, options) - unless do_not_enqueue?(klass, method_name) - options.symbolize_keys! + options.symbolize_keys! + unless do_not_enqueue?(klass, method_name, options) perform_in(options[:interval], klass, method_name, options) end end - def self.do_not_enqueue?(klass, method_name) - scheduled?(klass, method_name) || - enqueued?(klass, method_name) || - retrying?(klass, method_name) + def self.do_not_enqueue?(klass, method_name, options) + scheduled?(klass, method_name, options) || + enqueued?(klass, method_name, options) || + retrying?(klass, method_name, options) end - def self.retrying?(klass, method_name) + def self.retrying?(klass, method_name, options) ::Sidekiq::RetrySet.new.collect(&:item).select do |item| - matches_kass_and_method?(item, klass, method_name) + matches?(item, klass, method_name, options) end.present? end - def self.scheduled?(klass, method_name) + def self.scheduled?(klass, method_name, options) ::Sidekiq::ScheduledSet.new.collect(&:item).select do |item| - matches_kass_and_method?(item, klass, method_name) + matches?(item, klass, method_name, options) end.present? end - def self.enqueued?(klass, method_name) + def self.enqueued?(klass, method_name, options) ::Sidekiq::Queue.new("cron_job").collect(&:item).select do |item| - matches_kass_and_method?(item, klass, method_name) + matches?(item, klass, method_name, options) end.present? end - def self.matches_kass_and_method?(item, klass, method_name) - item["args"][0] == klass && item["args"][1] == method_name.to_s + def self.matches?(item, klass, method_name, options) + class_and_method_match?(item["args"], klass, method_name) && + at_match?(item["args"][2], options) + end + + def self.at_match?(arg_options, options) + return true unless !!arg_options["at"] && !!options[:at] + arg_options["at"] == options[:at] + end + + def self.class_and_method_match?(args, klass, method_name) + args[0] == klass && args[1] == method_name.to_s end def perform(klass, method_name, options) DelayedCron.process_job(klass, method_name, options) end