Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BatchProcessor ¶
BatchProcessor should be implemented to handle processing the batches of jobs. It is responsible for handling any errors / timeouts in the batch.
type Job ¶
type Job struct { ID string Data interface{} }
Job represents a single unit of work provided to the BatchProcessor.
type JobBatch ¶
type JobBatch struct {
// contains filtered or unexported fields
}
type MicroBatcher ¶
type MicroBatcher struct {
// contains filtered or unexported fields
}
MicroBatcher manages handling of the Job submission, batching the Job, and processing of it. When a Job is submitted, it is added to the batch and processed by the BatchProcessor if the batch size is reached. When the batchInterval is reached, the batch is processed regardless of the batch size. See Shutdown for details on shutdown.
func NewMicroBatcher ¶
func NewMicroBatcher(processor BatchProcessor, options ...Option) *MicroBatcher
NewMicroBatcher creates a new MicroBatcher with the provided BatchProcessor, batch size, and batch interval. The default batch size is 10, and the default batch interval is 3 minutes.
func (*MicroBatcher) Results ¶
func (mb *MicroBatcher) Results(context.Context) <-chan JobResult
Results returns a channel to receive the results of processing as JobResult. This channel is closed when Shutdown is called.
func (*MicroBatcher) Shutdown ¶
func (mb *MicroBatcher) Shutdown(context.Context) error
Shutdown stops the MicroBatcher and waits for all jobs to be processed. When calling Shutdown, the system processes the batch and sends the results to the results channel.
func (*MicroBatcher) Start ¶
func (mb *MicroBatcher) Start(context.Context)
Start initializes the processing loop for batching jobs. This will process the jobs in batches and send the results to the results channel. If shutdown is called, the processing loop will be stopped and the results channel will be shutdown.
type Option ¶
type Option func(*MicroBatcher)
Option for configuring the MicroBatcher.
func WithBatch ¶
WithBatch sets the batch for the MicroBatcher. This is how the jobs are batched together before being processed.
func WithBatchInterval ¶
WithBatchInterval sets the batch interval for the MicroBatcher. This is how often the batch is processed, regardless of the batch size.
func WithBatchSize ¶
WithBatchSize sets the batch size for the MicroBatcher. This is how many jobs are batched together before being processed.