Increase keepalive timeout. Add reconnection delay.

This commit is contained in:
Jay
2026-04-23 21:26:40 -04:00
parent 0ac8d9facd
commit 7e7b18bb2a
3 changed files with 34 additions and 9 deletions
+21 -1
View File
@@ -168,6 +168,7 @@ func WithWorkerFactory(wf WorkerFactory) PoolOption {
type WorkerConfig struct {
KeepaliveTimeout time.Duration
ReconnectDelay time.Duration
MaxQueueSize int
LoggingEnabled bool
LogLevel *slog.Level
@@ -188,7 +189,8 @@ func NewWorkerConfig(options ...WorkerOption) (*WorkerConfig, error) {
func GetDefaultWorkerConfig() *WorkerConfig {
return &WorkerConfig{
KeepaliveTimeout: 20 * time.Second,
KeepaliveTimeout: 60 * time.Second,
ReconnectDelay: 2 * time.Second,
MaxQueueSize: 0, // disabled by default
LoggingEnabled: true,
LogLevel: nil,
@@ -232,6 +234,13 @@ func validateKeepaliveTimeout(value time.Duration) error {
return nil
}
func validateReconnectDelay(value time.Duration) error {
if value < 0 {
return InvalidReconnectDelay
}
return nil
}
// When KeepaliveTimeout is set to zero, keepalive timeouts are disabled.
func WithKeepaliveTimeout(value time.Duration) WorkerOption {
return func(c *WorkerConfig) error {
@@ -244,6 +253,17 @@ func WithKeepaliveTimeout(value time.Duration) WorkerOption {
}
}
func WithReconnectDelay(value time.Duration) WorkerOption {
return func(c *WorkerConfig) error {
err := validateReconnectDelay(value)
if err != nil {
return err
}
c.ReconnectDelay = value
return nil
}
}
// When MaxQueueSize is set to zero, queue limits are disabled.
func WithMaxQueueSize(value int) WorkerOption {
return func(c *WorkerConfig) error {