-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Report indexing status to SDR during geo indexing
See #1299
- Loading branch information
1 parent
e0491c8
commit 5658c54
Showing
5 changed files
with
113 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,3 +43,4 @@ gem 'activesupport', '~> 7.0' | |
gem 'slop' | ||
|
||
gem 'factory_bot', '~> 6.2' | ||
gem 'dor-event-client' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'socket' | ||
|
||
# Reports indexing events to SDR via message queue | ||
# See: https://github.com/sul-dlss/dor-event-client | ||
# See also the HTTP API: https://sul-dlss.github.io/dor-services-app/#tag/events | ||
class SdrEvents | ||
class << self | ||
def configure( | ||
hostname: ENV.fetch('SDR_EVENTS_MQ_HOSTNAME', ::Settings.sdr_events.mq.hostname), | ||
vhost: ENV.fetch('SDR_EVENTS_MQ_VHOST', ::Settings.sdr_events.mq.vhost), | ||
username: ENV.fetch('SDR_EVENTS_MQ_USERNAME', ::Settings.sdr_events.mq.username), | ||
password: ENV.fetch('SDR_EVENTS_MQ_PASSWORD', ::Settings.sdr_events.mq.password) | ||
) | ||
Dor::Event::Client.configure(hostname:, vhost:, username:, password:) | ||
end | ||
|
||
def enabled? | ||
::Settings.sdr_events.enabled == true | ||
end | ||
|
||
# Item was added/updated in the index | ||
def report_indexing_success(druid) | ||
create_event(type: 'indexing_success', druid:) | ||
end | ||
|
||
# Item was removed from the index (e.g. via unrelease) | ||
def report_indexing_deleted(druid) | ||
create_event(type: 'indexing_deleted', druid:) | ||
end | ||
|
||
# Item has missing or inappropriately formatted metadata | ||
def report_indexing_skipped(druid, message:) | ||
create_event(type: 'indexing_skipped', druid:, data: { message: }) | ||
end | ||
|
||
# Exception was raised during indexing; provides optional context | ||
def report_indexing_errored(druid, message:, context: nil) | ||
create_event(type: 'indexing_errored', druid:, data: { message:, context: }.compact) | ||
end | ||
|
||
# Generic event creation; prefer more specific methods | ||
def create_event(druid:, type:, data: {}) | ||
Dor::Event::Client.create(type:, druid:, data: base_data.merge(data)) if enabled? | ||
end | ||
|
||
# Logged with every event | ||
def base_data | ||
@base_data ||= { | ||
host: Socket.gethostname, | ||
invoked_by: 'indexer' | ||
} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters