Class: Gitlab::EventStore::Subscription

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/event_store/subscription.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(worker, condition, delay) ⇒ Subscription

Returns a new instance of Subscription.



8
9
10
11
12
# File 'lib/gitlab/event_store/subscription.rb', line 8

def initialize(worker, condition, delay)
  @worker = worker
  @condition = condition
  @delay = delay
end

Instance Attribute Details

#conditionObject (readonly)

Returns the value of attribute condition.



6
7
8
# File 'lib/gitlab/event_store/subscription.rb', line 6

def condition
  @condition
end

#delayObject (readonly)

Returns the value of attribute delay.



6
7
8
# File 'lib/gitlab/event_store/subscription.rb', line 6

def delay
  @delay
end

#workerObject (readonly)

Returns the value of attribute worker.



6
7
8
# File 'lib/gitlab/event_store/subscription.rb', line 6

def worker
  @worker
end

Instance Method Details

#consume_event(event) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/gitlab/event_store/subscription.rb', line 14

def consume_event(event)
  return unless condition_met?(event)

  if delay
    worker.perform_in(delay, event.class.name, event.data.deep_stringify_keys)
  else
    worker.perform_async(event.class.name, event.data.deep_stringify_keys)
  end

  # We rescue and track any exceptions here because we don't want to
  # impact other subscribers if one is faulty.
  # The method `condition_met?`, since it can run a block, it might encounter
  # a bug. By raising an exception here we could interrupt the publishing
  # process, preventing other subscribers from consuming the event.
rescue StandardError => e
  Gitlab::ErrorTracking.track_and_raise_for_dev_exception(e, event_class: event.class.name, event_data: event.data)
end