Module: DelayedCronJob::ActiveJob::QueueAdapter

Defined in:
lib/delayed_cron_job/active_job/queue_adapter.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(klass) ⇒ Object



10
11
12
13
14
# File 'lib/delayed_cron_job/active_job/queue_adapter.rb', line 10

def self.extended(klass)
  meta = class << klass; self; end
  meta.send(:alias_method, :enqueue, :enqueue_with_cron)
  meta.send(:alias_method, :enqueue_at, :enqueue_at_with_cron)
end

.included(klass) ⇒ Object



5
6
7
8
# File 'lib/delayed_cron_job/active_job/queue_adapter.rb', line 5

def self.included(klass)
  klass.send(:alias_method, :enqueue, :enqueue_with_cron)
  klass.send(:alias_method, :enqueue_at, :enqueue_at_with_cron)
end

Instance Method Details

#enqueue_at_with_cron(job, timestamp) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/delayed_cron_job/active_job/queue_adapter.rb', line 20

def enqueue_at_with_cron(job, timestamp)
  options = { queue: job.queue_name,
              cron: job.cron  }
  options[:run_at] = Time.at(timestamp) if timestamp
  options[:priority] = job.priority if job.respond_to?(:priority)
  wrapper = ::ActiveJob::QueueAdapters::DelayedJobAdapter::JobWrapper.new(job.serialize)
  delayed_job = Delayed::Job.enqueue(wrapper, options)
  job.provider_job_id = delayed_job.id if job.respond_to?(:provider_job_id=)
  delayed_job
end

#enqueue_with_cron(job) ⇒ Object



16
17
18
# File 'lib/delayed_cron_job/active_job/queue_adapter.rb', line 16

def enqueue_with_cron(job)
  enqueue_at(job, nil)
end