worker

package module
v4.0.0-...-9148d33 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 25, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateSqsClient

func CreateSqsClient(awsConfigs ...*aws.Config) sqsiface.SQSAPI

CreateSqsClient creates a client for SQS API

Types

type Config

type Config struct {
	MaxNumberOfMessage int64
	QueueName          string
	QueueURL           string
	WaitTimeSecond     int64
}

Config struct

type Handler

type Handler interface {
	HandleMessage(msg *sqs.Message) error
}

Handler interface

type HandlerFunc

type HandlerFunc func(msg *sqs.Message) error

HandlerFunc is used to define the Handler that is run on for each message

func (HandlerFunc) HandleMessage

func (f HandlerFunc) HandleMessage(msg *sqs.Message) error

HandleMessage wraps a function for handling sqs messages

type InvalidEventError

type InvalidEventError struct {
	// contains filtered or unexported fields
}

InvalidEventError struct

func NewInvalidEventError

func NewInvalidEventError(event, msg string) InvalidEventError

NewInvalidEventError creates InvalidEventError struct

func (InvalidEventError) Error

func (e InvalidEventError) Error() string

type LoggerIFace

type LoggerIFace interface {
	Debug(i ...interface{})
	Info(i ...interface{})
	Error(i ...interface{})
}

LoggerIFace interface

type QueueAPI

type QueueAPI interface {
	GetQueueUrl(*sqs.GetQueueUrlInput) (*sqs.GetQueueUrlOutput, error)
	QueueDeleteReceiverAPI
}

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 QueueDeleteReceiverAPI

type QueueDeleteReceiverAPI interface {
	DeleteMessage(*sqs.DeleteMessageInput) (*sqs.DeleteMessageOutput, error)
	ReceiveMessage(*sqs.ReceiveMessageInput) (*sqs.ReceiveMessageOutput, error)
}

QueueDeleteReceiverAPI interface is the minimum interface required to run a worker. When a worker is in its Receive loop, it requires this interface.

type Worker

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

Worker struct

func New

func New(client QueueAPI, config *Config) *Worker

New sets up a new Worker

func (*Worker) Start

func (worker *Worker) Start(ctx context.Context, h Handler)

Start starts the polling and will continue polling till the application is forcibly stopped

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL