Class: Textus::Produce::Events

Inherits:
Object
  • Object
show all
Defined in:
lib/textus/produce/events.rb

Overview

Single home for the fetch lifecycle event vocabulary (ADR 0048 D5). Produce::Acquire::Intake (the ingest executor driven by reconcile + hook) emits through this seam so the event names and payload shapes live in one place with one derived hook context.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(events:, hook_context:) ⇒ Events

Returns a new instance of Events.



15
16
17
18
# File 'lib/textus/produce/events.rb', line 15

def initialize(events:, hook_context:)
  @events = events
  @hook_context = hook_context
end

Class Method Details

.from(container:, call:) ⇒ Object



8
9
10
11
12
13
# File 'lib/textus/produce/events.rb', line 8

def self.from(container:, call:)
  new(
    events: container.events,
    hook_context: Textus::Hooks::Context.for(container: container, call: call),
  )
end

Instance Method Details

#failed(key, error) ⇒ Object



24
25
26
27
# File 'lib/textus/produce/events.rb', line 24

def failed(key, error)
  @events.publish(:entry_fetch_failed, ctx: @hook_context, key: key,
                                       error_class: error.class.name, error_message: error.message)
end

#fetched(key, envelope, change) ⇒ Object



29
30
31
32
33
# File 'lib/textus/produce/events.rb', line 29

def fetched(key, envelope, change)
  return if change == :unchanged

  @events.publish(:entry_fetched, ctx: @hook_context, key: key, envelope: envelope, change: change)
end

#started(key, mode: :sync) ⇒ Object



20
21
22
# File 'lib/textus/produce/events.rb', line 20

def started(key, mode: :sync)
  @events.publish(:entry_fetch_started, ctx: @hook_context, key: key, mode: mode)
end