load balancer implementation, code refactoring

This commit is contained in:
2024-05-20 08:48:01 +02:00
parent fee7f86182
commit 472db89ea3
9 changed files with 122 additions and 29 deletions

View File

@@ -2,6 +2,7 @@ package internal
import (
"context"
"errors"
"log/slog"
evbus "github.com/asaskevich/EventBus"
@@ -21,18 +22,18 @@ type MessageQueue struct {
// By default it will be created with a size equals to nthe number of logical
// CPU cores -1.
// The queue size can be set via the qs flag.
func NewMessageQueue(l *slog.Logger) *MessageQueue {
func NewMessageQueue(l *slog.Logger) (*MessageQueue, error) {
qs := config.Instance().QueueSize
if qs <= 0 {
panic("invalid queue size")
return nil, errors.New("invalid queue size")
}
return &MessageQueue{
concurrency: qs,
eventBus: evbus.New(),
logger: l,
}
}, nil
}
// Publish a message to the queue and set the task to a peding state.