mirror of
https://blitiri.com.ar/repos/chasquid
synced 2026-01-27 20:45:56 +00:00
Make the max queue size and give up time configurable
Today, the maximum number of items in the queue, as well as how long we keep attempting to send each item, is hard-coded and not changed by end users. While they are totally adequate for chasquid's main use cases, it can still be useful for some users to change them. So this patch adds two new configuration options for those settings. They're marked experimental for now, so we can adjust them if needed after they get more exposure. Thanks to Lewis Ross-Jones <lewis_r_j@hotmail.com> for suggesting this improvement, and help with testing it.
This commit is contained in:
@@ -7,6 +7,7 @@ package config
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"blitiri.com.ar/go/log"
|
||||
|
||||
@@ -30,6 +31,9 @@ var defaultConfig = &Config{
|
||||
DropCharacters: proto.String("."),
|
||||
|
||||
MailLogPath: "<syslog>",
|
||||
|
||||
MaxQueueItems: 200,
|
||||
GiveUpSendAfter: "20h",
|
||||
}
|
||||
|
||||
// Load the config from the given file, with the given overrides.
|
||||
@@ -67,6 +71,12 @@ func Load(path, overrides string) (*Config, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// Validate the GiveUpSendAfter value.
|
||||
if _, err := time.ParseDuration(c.GiveUpSendAfter); err != nil {
|
||||
return nil, fmt.Errorf(
|
||||
"invalid give_up_send_after value %q: %v", c.GiveUpSendAfter, err)
|
||||
}
|
||||
|
||||
return c, nil
|
||||
}
|
||||
|
||||
@@ -126,6 +136,13 @@ func override(c, o *Config) {
|
||||
if o.HaproxyIncoming {
|
||||
c.HaproxyIncoming = true
|
||||
}
|
||||
|
||||
if o.MaxQueueItems > 0 {
|
||||
c.MaxQueueItems = o.MaxQueueItems
|
||||
}
|
||||
if o.GiveUpSendAfter != "" {
|
||||
c.GiveUpSendAfter = o.GiveUpSendAfter
|
||||
}
|
||||
}
|
||||
|
||||
// LogConfig logs the given configuration, in a human-friendly way.
|
||||
@@ -153,4 +170,13 @@ func LogConfig(c *Config) {
|
||||
log.Infof(" Dovecot auth: %v (%q, %q)",
|
||||
c.DovecotAuth, c.DovecotUserdbPath, c.DovecotClientPath)
|
||||
log.Infof(" HAProxy incoming: %v", c.HaproxyIncoming)
|
||||
log.Infof(" Max queue items: %d", c.MaxQueueItems)
|
||||
log.Infof(" Give up send after: %s", c.GiveUpSendAfterDuration())
|
||||
}
|
||||
|
||||
func (c *Config) GiveUpSendAfterDuration() time.Duration {
|
||||
// We validate the string value at config load time, so we know it is well
|
||||
// formed.
|
||||
d, _ := time.ParseDuration(c.GiveUpSendAfter)
|
||||
return d
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user