Class: Lyra::Projections::AsyncProjectionJob
- Inherits:
-
ActiveJob::Base
- Object
- ActiveJob::Base
- Lyra::Projections::AsyncProjectionJob
- Defined in:
- lib/lyra/projections/async_projection_job.rb
Overview
ActiveJob for asynchronous projection processing.
When projection_mode is :async, events are projected to model tables in background jobs rather than synchronously during the request.
Benefits:
- Faster response times (don't wait for projection)
- Better fault isolation (projection failures don't fail requests)
- Retry capability for transient failures
Trade-offs:
- Eventual consistency (reads may not see latest writes immediately)
- Requires background job infrastructure (Sidekiq, etc.)
Usage:
AsyncProjectionJob.perform_later(event_id, 'Registration', :create)
Instance Method Summary collapse
Instance Method Details
#perform(event_id, model_class_name, operation) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/lyra/projections/async_projection_job.rb', line 31 def perform(event_id, model_class_name, operation) event = load_event(event_id) return unless event model_class = model_class_name.constantize # Build a CommandResult-like structure from the event result = build_result_from_event(event, operation) # Project to model table ModelProjection.project(model_class, operation.to_sym, result) end |