Class: Embedding::ContentChangedHandler

Inherits:
ApplicationJob
  • Object
show all
Includes:
RailsEventStore::AsyncHandler
Defined in:
app/subscribers/embedding/content_changed_handler.rb

Overview

Async handler for Events::ContentEmbeddingRequired.

Every model that includes Models::Embeddable publishes this event from
its after_commit callback whenever embeddable content changes (title, body,
rule, description, transcript, etc.). This handler queues EmbeddingWorker
to regenerate the vector.

Using the event bus instead of a direct after_commit → EmbeddingWorker call
gives us:

  • Persistent audit trail: every regeneration trigger is a row in the
    event store, scoped to stream "Embedding$$".
  • Decoupling: models declare what happened; this handler decides the action.
  • Resilience: ActiveJob/Sidekiq retries on failure; the event record remains
    for replay or inspection.

Runs on the ai_embeddings queue to share the concurrency budget with the
embedding worker itself.

Instance Method Summary collapse

Instance Method Details

#perform(event) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/subscribers/embedding/content_changed_handler.rb', line 25

def perform(event)
  type = event.data[:embeddable_type]
  id   = event.data[:embeddable_id]

  unless type.present? && id.present?
    Rails.logger.warn '[Embedding::ContentChangedHandler] Missing embeddable_type or embeddable_id — skipping'
    return
  end

  Rails.logger.info "[Embedding::ContentChangedHandler] Queuing embedding for #{type}##{id}"
  EmbeddingWorker.perform_async(type, id)
rescue StandardError => e
  ErrorReporting.error(e)
  raise
end