Sha256: a6082a3e511c96336c5515e8c2a3c0f2504b6395a0c477cdca222275f2afcbc6

Contents?: true

Size: 891 Bytes

Versions: 2

Compression:

Stored size: 891 Bytes

Contents

require 'delayed_job'

module DelayedCron
  module Jobs
    class DelayedJob < Struct.new(:klass, :method_name, :options)

      def self.enqueue_delayed_cron(klass, method_name, options)
        unless scheduled?(klass, method_name)
          options.symbolize_keys!
          ::Delayed::Job.enqueue(
            :payload_object => new(klass, method_name, options),
            :run_at => Time.now + options[:interval],
            :queue => :cron_job
          )
        end
      end

      def self.scheduled?(klass, method_name)
        ::Delayed::Job.all.each do |job|
          obj = YAML.load(job.handler)
          scheduled = true if obj["klass"] == klass && obj["method_name"] == method_name
        end
        scheduled ||= false
      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.2 lib/delayed_cron/jobs/delayed_job.rb
delayed_cron-0.2.1 lib/delayed_cron/jobs/delayed_job.rb