Skip to content

Commit 8231a4e

Browse files
authored
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.
1 parent da8cbc1 commit 8231a4e

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

worker/worker.go

+10-3
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,25 @@ func NewInvalidEventError(event, msg string) InvalidEventError {
3838
return InvalidEventError{event: event, msg: msg}
3939
}
4040

41-
// QueueAPI interface is the minimum interface required from a queue implementation
41+
// QueueAPI interface is the minimum interface required from a queue implementation to invoke New worker.
42+
// Invoking worker.New() takes in a queue name which is why GetQueueUrl is needed.
4243
type QueueAPI interface {
43-
DeleteMessage(*sqs.DeleteMessageInput) (*sqs.DeleteMessageOutput, error)
4444
GetQueueUrl(*sqs.GetQueueUrlInput) (*sqs.GetQueueUrlOutput, error)
45+
QueueDeleteReceiverAPI
46+
}
47+
48+
// QueueDeleteReceiverAPI interface is the minimum interface required to run a worker.
49+
// When a worker is in its Receive loop, it requires this interface.
50+
type QueueDeleteReceiverAPI interface {
51+
DeleteMessage(*sqs.DeleteMessageInput) (*sqs.DeleteMessageOutput, error)
4552
ReceiveMessage(*sqs.ReceiveMessageInput) (*sqs.ReceiveMessageOutput, error)
4653
}
4754

4855
// Worker struct
4956
type Worker struct {
5057
Config *Config
5158
Log LoggerIFace
52-
SqsClient QueueAPI
59+
SqsClient QueueDeleteReceiverAPI
5360
}
5461

5562
// Config struct

0 commit comments

Comments
 (0)