rename queue config options
This commit is contained in:
@@ -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,
|
||||
|
||||
22
bot/queue.go
22
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
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user