From 8231a4e7ebe709ada886b26751926c625d58d6d8 Mon Sep 17 00:00:00 2001 From: Andrew Bernat <31580217+bernata@users.noreply.github.com> Date: Wed, 11 Nov 2020 12:57:22 -0800 Subject: [PATCH] Restrict the interface to run the worker. (#14) The worker needs DeleteMessage,ReceiveMessage in order to run. The worker needs GetQueueUrl only if it is being initialized with a queue name. --- worker/worker.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/worker/worker.go b/worker/worker.go index 3536c3c..93e2a7a 100644 --- a/worker/worker.go +++ b/worker/worker.go @@ -38,10 +38,17 @@ func NewInvalidEventError(event, msg string) InvalidEventError { return InvalidEventError{event: event, msg: msg} } -// QueueAPI interface is the minimum interface required from a queue implementation +// QueueAPI interface is the minimum interface required from a queue implementation to invoke New worker. +// Invoking worker.New() takes in a queue name which is why GetQueueUrl is needed. type QueueAPI interface { - DeleteMessage(*sqs.DeleteMessageInput) (*sqs.DeleteMessageOutput, error) GetQueueUrl(*sqs.GetQueueUrlInput) (*sqs.GetQueueUrlOutput, error) + QueueDeleteReceiverAPI +} + +// QueueDeleteReceiverAPI interface is the minimum interface required to run a worker. +// When a worker is in its Receive loop, it requires this interface. +type QueueDeleteReceiverAPI interface { + DeleteMessage(*sqs.DeleteMessageInput) (*sqs.DeleteMessageOutput, error) ReceiveMessage(*sqs.ReceiveMessageInput) (*sqs.ReceiveMessageOutput, error) } @@ -49,7 +56,7 @@ type QueueAPI interface { type Worker struct { Config *Config Log LoggerIFace - SqsClient QueueAPI + SqsClient QueueDeleteReceiverAPI } // Config struct