rename queue config options

This commit is contained in:
Aine
2022-11-15 09:45:43 +02:00
parent a8780a32c1
commit 4ef139f875
3 changed files with 31 additions and 31 deletions

View File

@@ -19,8 +19,8 @@ const (
commandDKIM = "dkim" commandDKIM = "dkim"
commandCatchAll = botOptionCatchAll commandCatchAll = botOptionCatchAll
commandUsers = botOptionUsers commandUsers = botOptionUsers
commandQueueItems = botOptionQueueItems commandQueueBatch = botOptionQueueBatch
commandQueueTries = botOptionQueueTries commandQueueRetries = botOptionQueueRetries
commandDelete = "delete" commandDelete = "delete"
commandMailboxes = "mailboxes" commandMailboxes = "mailboxes"
) )
@@ -184,13 +184,13 @@ func (b *Bot) initCommands() commandList {
allowed: b.allowAdmin, allowed: b.allowAdmin,
}, },
{ {
key: commandQueueItems, key: commandQueueBatch,
description: "max amount of emails to process on each queue check", description: "max amount of emails to process on each queue check",
sanitizer: utils.SanitizeIntString, sanitizer: utils.SanitizeIntString,
allowed: b.allowAdmin, allowed: b.allowAdmin,
}, },
{ {
key: commandQueueTries, key: commandQueueRetries,
description: "max amount of tries per email in queue before removal", description: "max amount of tries per email in queue before removal",
sanitizer: utils.SanitizeIntString, sanitizer: utils.SanitizeIntString,
allowed: b.allowAdmin, allowed: b.allowAdmin,

View File

@@ -5,8 +5,8 @@ import (
) )
const ( const (
defaultMaxQueueItems = 1 defaultQueueBatch = 1
defaultMaxQueueTries = 3 defaultQueueRetries = 3
) )
// ProcessQueue starts queue processing // ProcessQueue starts queue processing
@@ -14,23 +14,23 @@ func (b *Bot) ProcessQueue() {
b.log.Debug("staring queue processing...") b.log.Debug("staring queue processing...")
cfg := b.getBotSettings() cfg := b.getBotSettings()
maxItems := cfg.QueueItems() batchSize := cfg.QueueBatch()
if maxItems == 0 { if batchSize == 0 {
maxItems = defaultMaxQueueItems batchSize = defaultQueueBatch
} }
maxTries := cfg.QueueTries() retries := cfg.QueueRetries()
if maxTries == 0 { if retries == 0 {
maxTries = defaultMaxQueueTries retries = defaultQueueRetries
} }
b.popqueue(maxItems, maxTries) b.popqueue(batchSize, retries)
b.log.Debug("ended queue processing") b.log.Debug("ended queue processing")
} }
// popqueue gets emails from queue and tries to send them, // popqueue gets emails from queue and tries to send them,
// if an email was sent successfully - it will be removed from queue // if an email was sent successfully - it will be removed from queue
func (b *Bot) popqueue(maxItems, maxTries int) { func (b *Bot) popqueue(batchSize, maxTries int) {
b.lock(acQueueKey) b.lock(acQueueKey)
defer b.unlock(acQueueKey) defer b.unlock(acQueueKey)
index, err := b.lp.GetAccountData(acQueueKey) index, err := b.lp.GetAccountData(acQueueKey)
@@ -40,7 +40,7 @@ func (b *Bot) popqueue(maxItems, maxTries int) {
i := 0 i := 0
for id, itemkey := range index { for id, itemkey := range index {
if i > maxItems { if i > batchSize {
b.log.Debug("finished re-deliveries from queue") b.log.Debug("finished re-deliveries from queue")
return return
} }

View File

@@ -15,8 +15,8 @@ const (
botOptionCatchAll = "catch-all" botOptionCatchAll = "catch-all"
botOptionDKIMSignature = "dkim.pub" botOptionDKIMSignature = "dkim.pub"
botOptionDKIMPrivateKey = "dkim.pem" botOptionDKIMPrivateKey = "dkim.pem"
botOptionQueueItems = "queue:items" botOptionQueueBatch = "queue:batch"
botOptionQueueTries = "queue:tries" botOptionQueueRetries = "queue:retries"
) )
type botSettings map[string]string type botSettings map[string]string
@@ -60,14 +60,14 @@ func (s botSettings) DKIMPrivateKey() string {
return s.Get(botOptionDKIMPrivateKey) return s.Get(botOptionDKIMPrivateKey)
} }
// QueueItems option // QueueBatch option
func (s botSettings) QueueItems() int { func (s botSettings) QueueBatch() int {
return utils.Int(s.Get(botOptionQueueItems)) return utils.Int(s.Get(botOptionQueueBatch))
} }
// QueueTries option // QueueRetries option
func (s botSettings) QueueTries() int { func (s botSettings) QueueRetries() int {
return utils.Int(s.Get(botOptionQueueTries)) return utils.Int(s.Get(botOptionQueueRetries))
} }
func (b *Bot) initBotUsers() ([]string, error) { func (b *Bot) initBotUsers() ([]string, error) {