Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use Dor::TextExtraction::DorEventLogger consistently across the codebase for sending events #1418

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions lib/dor/text_extraction/abbyy/file_watcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module Abbyy
# See bin/abbyy_watcher for the script that starts this class
# See lib/capistrano/tasks/abbyy_watcher_systemd.cap for the systemd service definition
class FileWatcher
attr_reader :result_xml_path, :exceptions_path, :logger, :workflow_updater
attr_reader :result_xml_path, :exceptions_path, :logger, :workflow_updater, :dor_event_logger

# These methods control the underlying listener; see:
# https://github.com/guard/listen?tab=readme-ov-file#pause--start--stop
Expand All @@ -35,7 +35,7 @@ def initialize(
@logger = logger
@workflow_updater = workflow_updater_class.new(logger:)
@listener_options = default_listener_options.merge(listener_options)
Dor::Services::Client.configure(logger:, url: Settings.dor_services.url, token: Settings.dor_services.token)
@dor_event_logger = Dor::TextExtraction::DorEventLogger.new(logger:)
end
# rubocop:enable Metrics/AbcSize

Expand Down Expand Up @@ -76,8 +76,9 @@ def process_failure(results)
end

# Publish to the SDR event service with processing information
def create_event(type:, results:)
Dor::Services::Client.object("druid:#{results.druid}").events.create(
def create_event(type:, results:) # rubocop:disable Metrics/MethodLength
dor_event_logger.create_event(
druid: "druid:#{results.druid}",
type:,
data: {
host:,
Expand Down
14 changes: 6 additions & 8 deletions spec/lib/dor/text_extraction/abbyy/file_watcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
let(:druid) { "druid:#{bare_druid}" }
let(:logger) { instance_double(Logger) }
let(:workflow_updater) { instance_double(Dor::TextExtraction::WorkflowUpdater) }
let(:object_client) { instance_double(Dor::Services::Client::Object) }
let(:events_client) { instance_double(Dor::Services::Client::Events) }
let(:dor_event_logger) { instance_double(Dor::TextExtraction::DorEventLogger, create_event: nil) }
let(:listener_options) { { force_polling: true } }
let(:file_watcher) { described_class.new(logger:, listener_options:) }

Expand All @@ -21,12 +20,9 @@
)
allow(Dor::TextExtraction::WorkflowUpdater).to receive(:new).and_return(workflow_updater)
allow(Honeybadger).to receive(:notify)
allow(Dor::Services::Client).to receive(:configure)
allow(Dor::Services::Client).to receive(:object).and_return(object_client)
allow(Dor::TextExtraction::DorEventLogger).to receive(:new).with(logger:).and_return(dor_event_logger)
allow(workflow_updater).to receive(:mark_ocr_create_errored)
allow(workflow_updater).to receive(:mark_ocr_create_completed)
allow(object_client).to receive(:events).and_return(events_client)
allow(events_client).to receive(:create)
allow(logger).to receive(:info)
end

Expand Down Expand Up @@ -58,8 +54,9 @@
end

it 'publishes an event' do
expect(events_client).to have_received(:create).with(
expect(dor_event_logger).to have_received(:create_event).with(
{
druid:,
type: 'ocr_success',
data: a_hash_including({ software_name: 'ABBYY FineReader Server', software_version: '14.0' })
}
Expand Down Expand Up @@ -91,8 +88,9 @@
end

it 'publishes an event' do
expect(events_client).to have_received(:create).with(
expect(dor_event_logger).to have_received(:create_event).with(
{
druid:,
type: 'ocr_errored',
data: a_hash_including({ software_name: 'ABBYY FineReader Server', errors: failure_messages })
}
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/dor/text_extraction/dor_event_logger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
let(:data) { { a_result_message: 'for example, or some other helpful context' } }
let(:druid) { 'bc123df4567' }
let(:events_client) { instance_double(Dor::Services::Client::Events, create: nil) }
let(:dor_object) { instance_double(Dor::Services::Client::Object, events: events_client) }
let(:dor_object_client) { instance_double(Dor::Services::Client::Object, events: events_client) }

before do
allow(Dor::Services::Client).to receive(:object).with(druid).and_return(dor_object)
allow(Dor::Services::Client).to receive(:object).with(druid).and_return(dor_object_client)
allow(Dor::Services::Client).to receive(:configure)
end

Expand Down