Add progressive backoff function (#11497)
* [MM-15267] Utils: add backoff function to allow retries (#10958) * [MM-15267] Utils: add unit test and update retry logic (#10958) * [MM-15267] Utils: Add three retries to ProgressiveRetry (#10958) * [MM-15267] Utils: add comments for progressive retry (#10958) * [MM-15267] Utils: add license header to newly added file (#10958) * [MM-15267] Utils: fix typo (#10958) * [MM-15267] Utils: inline callback in function call (#10958) * [MM-15267] Utils: remove type definition for backoff callback function (#10958) * [MM-15267] Utils: use lookup table for timeout duration (#10958) * [MM-15267] Utils: table driven unit tests for Progressive Backoff (#10958) * [MM-15267] Utils: simplify retry function (#10958) * [MM-15267] Utils: add assert and require packages to test file (#10958) * [MM-15267] Utils: revert changes in go.mod and go.sum (#10958)
Этот коммит содержится в:
коммит произвёл
Jesse Hallam
родитель
903085feb8
Коммит
b464f31b38
@@ -4,9 +4,8 @@
|
||||
package plugin
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"github.com/mattermost/mattermost-server/utils"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
@@ -17,11 +16,20 @@ func (p *HelpersImpl) EnsureBot(bot *model.Bot) (retBotId string, retErr error)
|
||||
}
|
||||
|
||||
// If we fail for any reason, this could be a race between creation of bot and
|
||||
// retreval from anouther EnsureBot. Just try the basic retrieve existing again.
|
||||
// retrieval from another EnsureBot. Just try the basic retrieve existing again.
|
||||
defer func() {
|
||||
if retBotId == "" || retErr != nil {
|
||||
time.Sleep(time.Second)
|
||||
botIdBytes, err := p.API.KVGet(BOT_USER_KEY)
|
||||
var err error
|
||||
var botIdBytes []byte
|
||||
|
||||
err = utils.ProgressiveRetry(func() error {
|
||||
botIdBytes, err = p.API.KVGet(BOT_USER_KEY)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
if err == nil && botIdBytes != nil {
|
||||
retBotId = string(botIdBytes)
|
||||
retErr = nil
|
||||
|
||||
Ссылка в новой задаче
Block a user