Class: SidekiqPublisher::Publisher

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq_publisher/publisher.rb

Instance Method Summary collapse

Constructor Details

#initialize(instrumenter: Instrumenter.new) ⇒ Publisher

Returns a new instance of Publisher.



8
9
10
11
12
# File 'lib/sidekiq_publisher/publisher.rb', line 8

def initialize(instrumenter: Instrumenter.new)
  @instrumenter = instrumenter
  @client = SidekiqPublisher::Client.new
  @job_class_cache = {}
end

Instance Method Details

#publishObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/sidekiq_publisher/publisher.rb', line 14

def publish
  Job.unpublished_batches do |batch|
    instrumenter.instrument("publish_batch.publisher") do
      items = batch.map do |job|
        {
          "jid" => job[:job_id],
          "class" => lookup_job_class(job[:job_class]),
          "args" => job[:args],
          "at" => job[:run_at],
          "queue" => job[:queue],
          "wrapped" => job[:wrapped],
          "created_at" => job[:created_at].to_f,
        }.tap(&:compact!)
      end

      instrumenter.instrument("enqueue_batch.publisher") do |notification|
        enqueue_batch(batch, items, notification)
      end
    end
  end
  purge_expired_published_jobs
rescue StandardError => ex
  failure_warning(__method__, ex)
end