Class: EventDrivenWorkers::HhSearch::InventoryProducerWorker

Inherits:
ApplicationWorker
  • Object
show all
Defined in:
app/workers/event_driven_workers/hh_search/inventory_producer_worker.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.perform_conditionally(args = {}, async: true) ⇒ Object

Perform the job conditionally, with async option and compact params



8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/workers/event_driven_workers/hh_search/inventory_producer_worker.rb', line 8

def self.perform_conditionally(args = {}, async: true)
  return unless Flipper.enabled?(:kafka_producer_inventory_hhsearch)

  if async
    perform_async(args)
  else
    worker = new
    # Manual set a custom unique jid for synchronous execution
    worker.jid = SecureRandom.hex(12)
    worker.perform(args)
  end
end

Instance Method Details

#perform(args = {}) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/workers/event_driven_workers/hh_search/inventory_producer_worker.rb', line 21

def perform(args = {})
  if args.blank?
    HH_LOGGER.info('EventDrivenWorkers::HhSearch::InventoryProducerWorker: args is blank')
    return
  end

  args = args.with_indifferent_access
  topic = args[:topic]
  event_type = args[:event_type]
  object_id = args[:object_id]
  changed_attributes = normalize_changed_attributes(args[:changed_attributes])
  options = args.fetch(:options, {}).with_indifferent_access
  options[:batch_id] ||= jid

  producer = build_producer(topic, object_id, event_type, changed_attributes, options)
  producer.send_event
end