Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var (
ErrNoWorkToRetrieve = errors.New("no work to retrieve")
)
Functions ¶
This section is empty.
Types ¶
type HandleWorkError ¶
type HandleWorkError[T any] struct { ErrorMessage string WorkerID int Data T WorkTickerName string }
func NewHandleWorkError ¶
func NewHandleWorkError[T any](errorMessage string, workerID int, data T) HandleWorkError[T]
func (HandleWorkError[T]) Error ¶
func (hwe HandleWorkError[T]) Error() string
type Ticker ¶
type Ticker[T any] interface { AddWorkConfiguration(config WorkConfiguration[T]) Run(ctx context.Context) }
type WorkConfiguration ¶
type WorkConfiguration[T any] struct { Handler WorkHandler[T] Retriever WorkRetriever[T] }
WorkConfiguration is used to configure how work is retrieved and handled
type WorkHandler ¶
WorkHandler is a function that handles a single unit of work. It should do whatever processing is necessary. If an error is returned, that error is placed onto the error channel.
type WorkItem ¶
type WorkItem[T any] struct { Data T Handler WorkHandler[T] }
WorkItem is a single unit of work.
type WorkRetriever ¶
type WorkRetriever[T any] func(handler WorkHandler[T]) (WorkItem[T], error)
WorkRetriever is a function that returns a WorkItem and an error. It is used to retrieve work items on a tick.
type WorkTicker ¶
type WorkTicker[T any] struct { // contains filtered or unexported fields }
func NewWorkTicker ¶
func NewWorkTicker[T any](config WorkTickerConfig[T]) *WorkTicker[T]
NewWorkTicker creates a new WorkTicker instance of type T. Example:
workTicker := workticker.NewWorkTicker(workticker.WorkTickerConfig{
Logger: logrus.New().WithField("app", "example"),
NumWorkers: 10,
RateLimitPerSecond: 10,
TickFrequency: 5 * time.Second,
WorkErrorChan: errorChan,
WorkConfiguration: workticker.WorkConfiguration[MyData]{
Handler: handlerFunc,
Retriever: retrieverFunc,
},
})
ctx, cancel := context.WithCancel(context.Background())
go workTicker.Run(ctx)
// Wait for app to close or something...
cancel()
func (*WorkTicker[T]) Run ¶
func (wp *WorkTicker[T]) Run(ctx context.Context)
type WorkTickerConfig ¶
type WorkTickerConfig[T any] struct { Name string Logger *logrus.Entry NumWorkers int RateLimitPerSecond int TickFrequency time.Duration WorkErrorChan chan HandleWorkError[T] WorkConfiguration WorkConfiguration[T] }
Click to show internal directories.
Click to hide internal directories.