Skip to content

Commit

Permalink
Merge pull request #2301 from sul-dlss/okcomputer-🐇-check-and-misc-to…
Browse files Browse the repository at this point in the history
…uchups

Okcomputer 🐇 check and misc touchups
  • Loading branch information
justinlittman authored Jan 11, 2024
2 parents 601f78c + a41ea87 commit d73866d
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 2 deletions.
4 changes: 3 additions & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

# How was this change tested? 🤨

⚡ ⚠ If this change has cross service impact, or if it changes code used internally for cloud replication, **_run [integration test preassembly_image_accessioning_spec.rb](https://github.com/sul-dlss/infrastructure-integration-test/blob/main/spec/features/preassembly_image_accessioning_spec.rb) against stage as it tests preservation (including cloud replication)_**, and/or test in stage environment, in addition to specs. The main classes relevant to replication are `ZipmakerJob`, `DeliveryDispatcherJob`, `*DeliveryJob`, `ResultsRecorderJob`, and `DruidVersionZip`; [see here for overview diagram of replication pipeline](https://github.com/sul-dlss/preservation_catalog/wiki/Replication-Flow).⚡
⚡ ⚠ If this change has cross service impact, or if it changes code used internally for cloud replication, **_run [integration test preassembly_reaccessioning_spec.rb](https://github.com/sul-dlss/infrastructure-integration-test/blob/main/spec/features/preassembly_reaccessioning_spec.rb) against stage, as it tests preservation (including cloud replication)_**, and/or test manually in stage environment, in addition to specs.

The main classes relevant to replication are `ZipmakerJob`, `DeliveryDispatcherJob`, `*DeliveryJob`, `ResultsRecorderJob`, and `DruidVersionZip`; [see here for overview diagram of replication pipeline](https://github.com/sul-dlss/preservation_catalog/wiki/Replication-Flow).⚡



Expand Down
31 changes: 31 additions & 0 deletions config/initializers/okcomputer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,37 @@ def check
OkComputer::Registry.register "feature-#{name}-sdr2objects", DirectoryExistsCheck.new(sdrobjects_location, Settings.minimum_subfolder_count)
end

# Check that RabbitMQ queues exist
class RabbitQueueExistsCheck < OkComputer::Check
attr_reader :queue_names, :conn

def initialize(queue_names)
@queue_names = Array(queue_names)
@conn = Bunny.new(hostname: Settings.rabbitmq.hostname,
vhost: Settings.rabbitmq.vhost,
username: Settings.rabbitmq.username,
password: Settings.rabbitmq.password)
super()
end

def check
conn.start
status = conn.status
missing_queue_names = queue_names.reject { |queue_name| conn.queue_exists?(queue_name) }
if missing_queue_names.empty?
mark_message "'#{queue_names.join(', ')}' exists, connection status: #{status}"
else
mark_message "'#{missing_queue_names.join(', ')}' does not exist"
mark_failure
end
conn.close
rescue StandardError => e
mark_message "Error: '#{e}'"
mark_failure
end
end
OkComputer::Registry.register 'rabbit-queues', RabbitQueueExistsCheck.new('dsa.create-event')

OkComputer::Registry.register 'ruby_version', OkComputer::RubyVersionCheck.new

# ------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ services:
volumes:
- postgres-data:/var/lib/postgresql/data
redis:
image: redis:3
image: redis:7
command: redis-server
ports:
- 6379:6379
Expand Down
31 changes: 31 additions & 0 deletions spec/config/okcomputer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,35 @@
expect(described_class.new('i-do-not-exist')).not_to be_successful
end
end

describe RabbitQueueExistsCheck do
let(:bunny_conn) { instance_double(Bunny::Session) }
let(:queue_name1) { 'foo.first_queue' }
let(:queue_name2) { 'foo.second_queue' }

before do
allow(bunny_conn).to receive_messages(start: bunny_conn, status: :open, close: true)
allow(bunny_conn).to receive(:queue_exists?).with(queue_name1).and_return(queue_exists1)
allow(bunny_conn).to receive(:queue_exists?).with(queue_name2).and_return(queue_exists2)
allow(Bunny).to receive(:new).and_return(bunny_conn)
end

context 'when the expected queues are present' do
let(:queue_exists1) { true }
let(:queue_exists2) { true }

it 'succeeds if the expected queue exists' do
expect(described_class.new([queue_name1, queue_name2])).to be_successful
end
end

context 'when a queue is missing' do
let(:queue_exists1) { true }
let(:queue_exists2) { false }

it 'succeeds if the expected queue exists' do
expect(described_class.new([queue_name1, queue_name2])).not_to be_successful
end
end
end
end

0 comments on commit d73866d

Please sign in to comment.