Skip to content

Commit

Permalink
Restrict the interface to run the worker. (#14)
Browse files Browse the repository at this point in the history
The worker needs DeleteMessage,ReceiveMessage in order to run.
The worker needs GetQueueUrl only if it is being initialized with a queue name.
  • Loading branch information
bernata authored Nov 11, 2020
1 parent da8cbc1 commit 8231a4e
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,25 @@ 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)
}

// Worker struct
type Worker struct {
Config *Config
Log LoggerIFace
SqsClient QueueAPI
SqsClient QueueDeleteReceiverAPI
}

// Config struct
Expand Down

0 comments on commit 8231a4e

Please sign in to comment.