Class: Textus::Write::FetchEvents

Inherits:
Object
  • Object
show all
Defined in:
lib/textus/write/fetch_events.rb

Overview

Single home for the fetch lifecycle event vocabulary (ADR 0048 D5). Both FetchWorker (synchronous semantics) and FetchOrchestrator (async policy) emit 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:) ⇒ FetchEvents

Returns a new instance of FetchEvents.



15
16
17
18
# File 'lib/textus/write/fetch_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/write/fetch_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

#backgrounded(key, started_at:, budget_ms:) ⇒ Object



35
36
37
38
39
# File 'lib/textus/write/fetch_events.rb', line 35

def backgrounded(key, started_at:, budget_ms:)
  payload = { key: key, started_at: started_at, budget_ms: budget_ms }
  payload[:ctx] = @hook_context if @hook_context
  @events.publish(:fetch_backgrounded, **payload)
end

#failed(key, error) ⇒ Object



24
25
26
27
# File 'lib/textus/write/fetch_events.rb', line 24

def failed(key, error)
  @events.publish(: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/write/fetch_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/write/fetch_events.rb', line 20

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