Skip to content

Commit

Permalink
Merge pull request #52 from alphagov/configurable-repo
Browse files Browse the repository at this point in the history
Use Google Discovery Engine repository
  • Loading branch information
csutter authored Oct 18, 2023
2 parents 2edff70 + 43b2506 commit b28231d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
31 changes: 31 additions & 0 deletions lib/repositories/google_discovery_engine/repository.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module Repositories
module GoogleDiscoveryEngine
# A repository integrating with Google Discovery Engine
# TODO: This is just a copy of the Null repository to start off with, but it should be updated
# to integrate with the real product.
class Repository
def initialize(logger: Logger.new($stdout, progname: self.class.name))
@logger = logger
end

def put(content_id, metadata, content: nil, payload_version: nil)
content_snippet = content ? content[0..50] : "<no content>"

logger.info(
sprintf(
"[PUT %s@v%s] %s: '%s...'",
content_id, payload_version, metadata[:link], content_snippet
),
)
end

def delete(content_id, payload_version: nil)
logger.info(sprintf("[DELETE %s@v%s]", content_id, payload_version))
end

private

attr_reader :logger
end
end
end
7 changes: 2 additions & 5 deletions lib/tasks/document_sync_worker.rake
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require "document_sync_worker"
require "repositories/null/repository"
require "repositories/google_discovery_engine/repository"

namespace :document_sync_worker do
desc "Create RabbitMQ queue for development environment"
Expand All @@ -18,10 +18,7 @@ namespace :document_sync_worker do
desc "Listens to and processes messages from the published documents queue"
task run: :environment 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 = Repositories::Null::Repository.new(logger: config.logger)
config.repository = Repositories::GoogleDiscoveryEngine::Repository.new(logger: config.logger)
config.message_queue_name = ENV.fetch("PUBLISHED_DOCUMENTS_MESSAGE_QUEUE_NAME")
end

Expand Down

0 comments on commit b28231d

Please sign in to comment.