Class: BackgroundJobs::Sidekiq::JobQueue

Inherits:
Object
  • Object
show all
Defined in:
lib/background_jobs/strategies/sidekiq/job_queue.rb

Instance Method Summary collapse

Instance Method Details

#enqueue(job_type, job_id, attributes, options = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/background_jobs/strategies/sidekiq/job_queue.rb', line 10

def enqueue(job_type, job_id, attributes, options = {})
  priority = options[:priority] || 1
  unique = options[:unique] || false
  at = (Time.now + options[:in]).to_i if options[:in]

  return if unique && is_scheduled?(job_type)

  queue = BackgroundJobs.job_registry.get_type(job_type)
  attributes.unshift job_id
  attributes.unshift job_type

  args = {
    'queue' => queue.to_s, # queue by priority?
    'class' => JobAdapter,
    'args' => JobAttributesAdapter.new(attributes).encode
  }

  args['at'] = at if at

  ::Sidekiq::Client.push(args)
end