Class: Publication::VisionAnalysisHandler

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

Overview

Async handler for Events::PublicationPdfChanged.

Queues PublicationVisionWorker whenever a publication's PDF attachment is
linked or replaced. The worker sends the full PDF to Claude AI, which reads
all pages (including vector diagrams, photos, and tables) and writes a
structured description to pdf_image_descriptions. EmbeddingWorker is then
triggered automatically by the worker to regenerate the semantic embedding
with the new content.

Runs on the ai_embeddings queue to co-locate with the vision worker and
respect the same concurrency budget.

Instance Method Summary collapse

Instance Method Details

#perform(event) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'app/subscribers/publication/vision_analysis_handler.rb', line 19

def perform(event)
  item_id = event.data[:item_id]
  item = Item.find_by(id: item_id)
  return unless item&.is_publication?

  Rails.logger.info "[Publication::VisionAnalysisHandler] Queuing vision analysis for Publication #{item_id}"
  PublicationVisionWorker.perform_async(item_id, { 'force' => true })
rescue StandardError => e
  ErrorReporting.error(e)
  raise
end