Class: SourceMonitor::Fetching::Completion::EventPublisher
- Inherits:
-
Object
- Object
- SourceMonitor::Fetching::Completion::EventPublisher
- Defined in:
- lib/source_monitor/fetching/completion/event_publisher.rb
Overview
Publishes fetch completion events to the configured event dispatcher.
Defined Under Namespace
Classes: Result
Instance Method Summary collapse
- #call(source:, result:) ⇒ Object
-
#initialize(dispatcher: SourceMonitor::Events) ⇒ EventPublisher
constructor
A new instance of EventPublisher.
Constructor Details
#initialize(dispatcher: SourceMonitor::Events) ⇒ EventPublisher
Returns a new instance of EventPublisher.
14 15 16 |
# File 'lib/source_monitor/fetching/completion/event_publisher.rb', line 14 def initialize(dispatcher: SourceMonitor::Events) @dispatcher = dispatcher end |
Instance Method Details
#call(source:, result:) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/source_monitor/fetching/completion/event_publisher.rb', line 18 def call(source:, result:) dispatcher.after_fetch_completed(source: source, result: result) Result.new(status: :published) rescue StandardError => error Rails.logger.error( "[SourceMonitor::Fetching::Completion::EventPublisher] Event dispatch failed for source #{source.id}: #{error.class} - #{error.}" ) if defined?(Rails) && Rails.respond_to?(:logger) && Rails.logger Result.new(status: :failed, error: error) end |