diff --git a/bot/command.go b/bot/command.go index 9c7c88c..40a6035 100644 --- a/bot/command.go +++ b/bot/command.go @@ -13,16 +13,16 @@ import ( ) const ( - commandHelp = "help" - commandStop = "stop" - commandSend = "send" - commandDKIM = "dkim" - commandCatchAll = botOptionCatchAll - commandUsers = botOptionUsers - commandQueueItems = botOptionQueueItems - commandQueueTries = botOptionQueueTries - commandDelete = "delete" - commandMailboxes = "mailboxes" + commandHelp = "help" + commandStop = "stop" + commandSend = "send" + commandDKIM = "dkim" + commandCatchAll = botOptionCatchAll + commandUsers = botOptionUsers + commandQueueBatch = botOptionQueueBatch + commandQueueRetries = botOptionQueueRetries + commandDelete = "delete" + commandMailboxes = "mailboxes" ) type ( @@ -184,13 +184,13 @@ func (b *Bot) initCommands() commandList { allowed: b.allowAdmin, }, { - key: commandQueueItems, + key: commandQueueBatch, description: "max amount of emails to process on each queue check", sanitizer: utils.SanitizeIntString, allowed: b.allowAdmin, }, { - key: commandQueueTries, + key: commandQueueRetries, description: "max amount of tries per email in queue before removal", sanitizer: utils.SanitizeIntString, allowed: b.allowAdmin, diff --git a/bot/queue.go b/bot/queue.go index b35b33a..865c097 100644 --- a/bot/queue.go +++ b/bot/queue.go @@ -5,8 +5,8 @@ import ( ) const ( - defaultMaxQueueItems = 1 - defaultMaxQueueTries = 3 + defaultQueueBatch = 1 + defaultQueueRetries = 3 ) // ProcessQueue starts queue processing @@ -14,23 +14,23 @@ func (b *Bot) ProcessQueue() { b.log.Debug("staring queue processing...") cfg := b.getBotSettings() - maxItems := cfg.QueueItems() - if maxItems == 0 { - maxItems = defaultMaxQueueItems + batchSize := cfg.QueueBatch() + if batchSize == 0 { + batchSize = defaultQueueBatch } - maxTries := cfg.QueueTries() - if maxTries == 0 { - maxTries = defaultMaxQueueTries + retries := cfg.QueueRetries() + if retries == 0 { + retries = defaultQueueRetries } - b.popqueue(maxItems, maxTries) + b.popqueue(batchSize, retries) b.log.Debug("ended queue processing") } // popqueue gets emails from queue and tries to send them, // 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) defer b.unlock(acQueueKey) index, err := b.lp.GetAccountData(acQueueKey) @@ -40,7 +40,7 @@ func (b *Bot) popqueue(maxItems, maxTries int) { i := 0 for id, itemkey := range index { - if i > maxItems { + if i > batchSize { b.log.Debug("finished re-deliveries from queue") return } diff --git a/bot/settings_bot.go b/bot/settings_bot.go index c17dc64..b54d783 100644 --- a/bot/settings_bot.go +++ b/bot/settings_bot.go @@ -15,8 +15,8 @@ const ( botOptionCatchAll = "catch-all" botOptionDKIMSignature = "dkim.pub" botOptionDKIMPrivateKey = "dkim.pem" - botOptionQueueItems = "queue:items" - botOptionQueueTries = "queue:tries" + botOptionQueueBatch = "queue:batch" + botOptionQueueRetries = "queue:retries" ) type botSettings map[string]string @@ -60,14 +60,14 @@ func (s botSettings) DKIMPrivateKey() string { return s.Get(botOptionDKIMPrivateKey) } -// QueueItems option -func (s botSettings) QueueItems() int { - return utils.Int(s.Get(botOptionQueueItems)) +// QueueBatch option +func (s botSettings) QueueBatch() int { + return utils.Int(s.Get(botOptionQueueBatch)) } -// QueueTries option -func (s botSettings) QueueTries() int { - return utils.Int(s.Get(botOptionQueueTries)) +// QueueRetries option +func (s botSettings) QueueRetries() int { + return utils.Int(s.Get(botOptionQueueRetries)) } func (b *Bot) initBotUsers() ([]string, error) {