Class: DurableFlow::EventSubscriber

Inherits:
Object
  • Object
show all
Defined in:
lib/durable_flow/event_subscriber.rb

Instance Method Summary collapse

Instance Method Details

#emit(event) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/durable_flow/event_subscriber.rb', line 5

def emit(event)
  return unless DurableFlow.database_ready?
  return if Fiber[:durable_flow_recording_event]

  Fiber[:durable_flow_recording_event] = true
  workflow_event = WorkflowEvent.create!(
    name: event.fetch(:name).to_s,
    payload: Serializer.dump(event[:payload] || {}),
    tags: Serializer.dump(event[:tags] || {}),
    context: Serializer.dump(event[:context] || {}),
    source_location: Serializer.dump(event[:source_location] || {}),
    occurred_at: occurred_at(event[:timestamp]),
  )

  Dispatcher.dispatch(workflow_event)
ensure
  Fiber[:durable_flow_recording_event] = false
end