Sha256: 5b52166a22f79f9fb68909b87bc74f2650bc7c013ba712c2c692602c1902f5d4

Contents?: true

Size: 933 Bytes

Versions: 9

Compression:

Stored size: 933 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)
        scheduled = false
        ::Delayed::Job.where(:queue => :cron_job).each do |job|
          obj = YAML.load_dj(job.handler)
          scheduled = true if obj["klass"] == klass && obj["method_name"] == method_name
        end
        scheduled
      end

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

    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
delayed_cron-0.2.11 lib/delayed_cron/jobs/delayed_job.rb
delayed_cron-0.2.10 lib/delayed_cron/jobs/delayed_job.rb
delayed_cron-0.2.9 lib/delayed_cron/jobs/delayed_job.rb
delayed_cron-0.2.8 lib/delayed_cron/jobs/delayed_job.rb
delayed_cron-0.2.7 lib/delayed_cron/jobs/delayed_job.rb
delayed_cron-0.2.6 lib/delayed_cron/jobs/delayed_job.rb
delayed_cron-0.2.5 lib/delayed_cron/jobs/delayed_job.rb
delayed_cron-0.2.4 lib/delayed_cron/jobs/delayed_job.rb
delayed_cron-0.2.3 lib/delayed_cron/jobs/delayed_job.rb