Skip to content

Commit

Permalink
Merge pull request #37 from alphagov/sync
Browse files Browse the repository at this point in the history
Rename `PublishingEventPipeline` to `DocumentSyncWorker`
  • Loading branch information
csutter authored Oct 6, 2023
2 parents bead05f + d20db95 commit 3c3a23d
Show file tree
Hide file tree
Showing 18 changed files with 59 additions and 59 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ gem "railties", RAILS_GEMS_VERSION
gem "bootsnap", require: false
gem "govuk_app_config"

# Gems for publishing_event_pipeline
# Gems for document_sync_worker
gem "govuk_message_queue_consumer", require: false
gem "jsonpath", require: false
gem "plek", require: false
Expand Down
30 changes: 30 additions & 0 deletions lib/document_sync_worker.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
require "govuk_message_queue_consumer"
require "jsonpath"
require "plek"

require "document_sync_worker/configuration"
require "document_sync_worker/message_processor"

require "document_sync_worker/document"
require "document_sync_worker/document/base"
require "document_sync_worker/document/publish"
require "document_sync_worker/document/unpublish"

module DocumentSyncWorker
def self.configuration
@configuration ||= Configuration.new
end

def self.configure
yield(configuration)
end

def self.run
GovukMessageQueueConsumer::Consumer.new(
queue_name: DocumentSyncWorker.configuration.message_queue_name,
processor: DocumentSyncWorker::MessageProcessor.new(
repository: configuration.repository,
),
).run
end
end
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module PublishingEventPipeline
module DocumentSyncWorker
class Configuration
attr_accessor :logger, :message_queue_name, :repository

def initialize
@logger = Logger.new($stdout, progname: "PublishingEventPipeline")
@logger = Logger.new($stdout, progname: "DocumentSyncWorker")
end
end
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module PublishingEventPipeline
module DocumentSyncWorker
module Document
# When a document is unpublished in the source system, its document type changes to one of
# these values. While semantically different for other systems, we only need to know that they
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module PublishingEventPipeline
module DocumentSyncWorker
module Document
# Abstract base class for documents that can be synchronized to a repository.
class Base
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module PublishingEventPipeline
module DocumentSyncWorker
module Document
class Publish < Base
# All the possible keys in the message hash that can contain unstructured content that we want
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module PublishingEventPipeline
module DocumentSyncWorker
module Document
class Unpublish < Base
# Synchronize the document to the given repository (i.e. delete it from the repository).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module PublishingEventPipeline
module DocumentSyncWorker
# Processes incoming content changes from the publishing message queue.
class MessageProcessor
attr_reader :repository
Expand Down
30 changes: 0 additions & 30 deletions lib/publishing_event_pipeline.rb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require "publishing_event_pipeline"
require "document_sync_worker"
require "search_repositories/null/null_repository"

# TODO: For now, this lives within the application repository, but we may want to extract it to a
Expand All @@ -9,7 +9,7 @@ require "search_repositories/null/null_repository"
# implicit dependencies on the Rails application.
#
# rubocop:disable Rails/RakeEnvironment
namespace :publishing_event_pipeline do
namespace :document_sync_worker do
desc "Create RabbitMQ queue for development environment"
task :create_queue do
# The exchange, queue, and binding are created via Terraform outside of local development:
Expand All @@ -20,20 +20,20 @@ namespace :publishing_event_pipeline do
bunny = Bunny.new
channel = bunny.start.create_channel
exch = Bunny::Exchange.new(channel, :topic, "published_documents")
channel.queue(ENV.fetch("PUBLISHING_EVENT_MESSAGE_QUEUE_NAME")).bind(exch, routing_key: "*.*")
channel.queue(ENV.fetch("PUBLISHED_DOCUMENTS_MESSAGE_QUEUE_NAME")).bind(exch, routing_key: "*.*")
end

desc "Listens to and processes messages from the published documents queue"
task :process_messages do
PublishingEventPipeline.configure do |config|
task :run do
DocumentSyncWorker.configure do |config|
# TODO: Once we have access to the search product and written a repository for it, this should
# be set to the real repository. Until then, this allows us to verify that the pipeline is
# working as expected through the logs.
config.repository = SearchRepositories::Null::NullRepository.new
config.message_queue_name = ENV.fetch("PUBLISHING_EVENT_MESSAGE_QUEUE_NAME")
config.message_queue_name = ENV.fetch("PUBLISHED_DOCUMENTS_MESSAGE_QUEUE_NAME")
end

PublishingEventPipeline.run
DocumentSyncWorker.run
end
end
# rubocop:enable Rails/RakeEnvironment
4 changes: 2 additions & 2 deletions spec/integration/publishing_event_pipeline_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
require "govuk_message_queue_consumer/test_helpers"

RSpec.describe "Publishing event pipeline" do
let(:repository) { PublishingEventPipeline::Repositories::TestRepository.new(documents) }
let(:repository) { DocumentSyncWorker::Repositories::TestRepository.new(documents) }
let(:message) { GovukMessageQueueConsumer::MockMessage.new(payload) }

before do
PublishingEventPipeline::MessageProcessor.new(repository:).process(message)
DocumentSyncWorker::MessageProcessor.new(repository:).process(message)
end

describe "for a 'press_release' message" do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
RSpec.describe PublishingEventPipeline::Document::Publish do
RSpec.describe DocumentSyncWorker::Document::Publish do
subject(:document) { described_class.new(document_hash) }

let(:repository) do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
RSpec.describe PublishingEventPipeline::Document::Unpublish do
RSpec.describe DocumentSyncWorker::Document::Unpublish do
subject(:document) { described_class.new(document_hash) }

let(:repository) do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
RSpec.describe PublishingEventPipeline::Document do
RSpec.describe DocumentSyncWorker::Document do
describe ".for" do
subject(:document) { described_class.for(document_hash) }

Expand All @@ -8,14 +8,14 @@
context "when the document type is #{document_type}" do
let(:document_type) { document_type }

it { is_expected.to be_a(PublishingEventPipeline::Document::Unpublish) }
it { is_expected.to be_a(DocumentSyncWorker::Document::Unpublish) }
end
end

context "when the document type is not one of the unpublish document types" do
let(:document_type) { "anything-else" }

it { is_expected.to be_a(PublishingEventPipeline::Document::Publish) }
it { is_expected.to be_a(DocumentSyncWorker::Document::Publish) }
end
end
end
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "govuk_message_queue_consumer"
require "govuk_message_queue_consumer/test_helpers"

RSpec.describe PublishingEventPipeline::MessageProcessor do
RSpec.describe DocumentSyncWorker::MessageProcessor do
subject(:processor) { described_class.new(repository:) }

let(:repository) { double }
Expand All @@ -15,7 +15,7 @@

before do
allow(Rails.logger).to receive(:info)
allow(PublishingEventPipeline::Document).to receive(:for).with(payload).and_return(document)
allow(DocumentSyncWorker::Document).to receive(:for).with(payload).and_return(document)
end

it "acks incoming messages" do
Expand All @@ -32,7 +32,7 @@

context "when creating the document fails" do
before do
allow(PublishingEventPipeline::Document).to receive(:for).and_raise("Something went wrong")
allow(DocumentSyncWorker::Document).to receive(:for).and_raise("Something went wrong")
end

it "bubbles the error up and does not ack the message" do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "govuk_message_queue_consumer"

RSpec.describe PublishingEventPipeline do
RSpec.describe DocumentSyncWorker do
describe ".run" do
let(:consumer) { instance_double(GovukMessageQueueConsumer::Consumer, run: nil) }
let(:repository) { double }
Expand All @@ -13,7 +13,7 @@

allow(GovukMessageQueueConsumer::Consumer).to receive(:new).with(
queue_name: "test-queue",
processor: an_instance_of(PublishingEventPipeline::MessageProcessor),
processor: an_instance_of(DocumentSyncWorker::MessageProcessor),
).and_return(consumer)
end

Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

# TODO: If the write side of this application is extracted to a separate unit, we will need to
# remove this, otherwise it can be made permanent.
require "publishing_event_pipeline"
require "document_sync_worker"

# See https://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
RSpec.configure do |config|
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module PublishingEventPipeline
module DocumentSyncWorker
module Repositories
# A fake repository for end-to-end testing purposes
class TestRepository
Expand Down

0 comments on commit 3c3a23d

Please sign in to comment.