mirror of
https://github.com/Luzifer/twitch-bot.git
synced 2024-12-30 08:31:16 +00:00
Knut Ahlers
f684abc29f
which might be a false-negative and re-added later Signed-off-by: Knut Ahlers <knut@ahlers.me>
28 lines
699 B
Go
28 lines
699 B
Go
package helpers
|
|
|
|
import (
|
|
"github.com/Luzifer/go_helpers/v2/backoff"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
const (
|
|
maxRetries = 5
|
|
)
|
|
|
|
// Retry contains a standard set of configuration parameters for an
|
|
// exponential backoff to be used throughout the bot
|
|
func Retry(fn func() error) error {
|
|
//nolint:wrapcheck
|
|
return backoff.NewBackoff().
|
|
WithMaxIterations(maxRetries).
|
|
Retry(fn)
|
|
}
|
|
|
|
// RetryTransaction takes a database object and a function acting on
|
|
// the database. The function will be run in a transaction on the
|
|
// database and will be retried as if executed using Retry
|
|
func RetryTransaction(db *gorm.DB, fn func(tx *gorm.DB) error) error {
|
|
return Retry(func() error {
|
|
return db.Transaction(fn)
|
|
})
|
|
}
|