Class: GoodJob::Adapter

Inherits:
Object
  • Object
show all
Defined in:
lib/good_job/adapter.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Adapter

Returns a new instance of Adapter.



3
4
5
6
# File 'lib/good_job/adapter.rb', line 3

def initialize(options = {})
  @options = options
  @scheduler = InlineScheduler.new if inline?
end

Instance Method Details

#enqueue(job) ⇒ Object



12
13
14
# File 'lib/good_job/adapter.rb', line 12

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

#enqueue_at(job, timestamp) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/good_job/adapter.rb', line 16

def enqueue_at(job, timestamp)
  params = {
    queue_name: job.queue_name,
    priority: job.priority,
    serialized_params: job.serialize,
  }
  params[:scheduled_at] = Time.at(timestamp) if timestamp

  good_job = GoodJob::Job.create(params)
  @scheduler.enqueue(good_job) if inline?
end

#inline?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/good_job/adapter.rb', line 8

def inline?
  @options.fetch(:inline, false)
end

#shutdown(wait: true) ⇒ Object



28
29
30
# File 'lib/good_job/adapter.rb', line 28

def shutdown(wait: true)
  @scheduler&.shutdown(wait: wait)
end