Sha256: 6a1836a1d727c427da697eaa18c110ac2fb63e237eefbd23e71ee05ff369f89d

Contents?: true

Size: 808 Bytes

Versions: 2

Compression:

Stored size: 808 Bytes

Contents

require 'sidekiq/worker'

module DelayedCron
  module Jobs
    class Sidekiq
      include ::Sidekiq::Worker
      sidekiq_options :queue => :cron_job

      def self.enqueue_delayed_cron(klass, method_name, options)
        unless scheduled?(klass, method_name)
          options.symbolize_keys!
          perform_in(options[:interval], klass, method_name, options)
        end
      end

      def self.scheduled?(klass, method_name)
        items = []
        ::Sidekiq::ScheduledSet.new.each { |job| items << job.item }
        items.select do |item|
          item["args"][0] == klass &&
          item["args"][1] == method_name.to_s
        end.present?
      end

      def perform(klass, method_name, options)
        DelayedCron.process_job(klass, method_name, options)
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
delayed_cron-0.2.1 lib/delayed_cron/jobs/sidekiq.rb
delayed_cron-0.2.0 lib/delayed_cron/jobs/sidekiq.rb