Sha256: fdfa327f492024e00d816debfbe0ab05a8c6eb0e7c4676697842fc143ae5382a

Contents?: true

Size: 830 Bytes

Versions: 4

Compression:

Stored size: 830 Bytes

Contents

require 'sidekiq/worker'
require 'sidekiq/api'

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

4 entries across 4 versions & 1 rubygems

Version Path
delayed_cron-0.2.5 lib/delayed_cron/jobs/sidekiq.rb
delayed_cron-0.2.4 lib/delayed_cron/jobs/sidekiq.rb
delayed_cron-0.2.3 lib/delayed_cron/jobs/sidekiq.rb
delayed_cron-0.2.2 lib/delayed_cron/jobs/sidekiq.rb