Work on failed outbound requests and move type migrators
- DB type migrators are now in separate file, in preparation for full custom sql migration statements - Start work on handling failed outbound requests stored in the db
This commit is contained in:
parent
81a01fbf8b
commit
7ac4c628b8
13 changed files with 372 additions and 145 deletions
|
@ -7,6 +7,7 @@ package dbgen
|
|||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"strings"
|
||||
|
||||
"git.mstar.dev/mstar/linstrom/storage-new/models"
|
||||
"gorm.io/gorm"
|
||||
|
@ -607,6 +608,34 @@ type IFailedOutboundRequestDo interface {
|
|||
Returning(value interface{}, columns ...string) IFailedOutboundRequestDo
|
||||
UnderlyingDB() *gorm.DB
|
||||
schema.Tabler
|
||||
|
||||
KillServers(maxAttempts uint32) (err error)
|
||||
}
|
||||
|
||||
// KillServers marks all servers where a request has more than X failed attempts as dead
|
||||
//
|
||||
// WITH servers_to_kill AS (
|
||||
//
|
||||
// SELECT target_server_id
|
||||
// FROM failed_outbound_requests
|
||||
// WHERE nr_of_attempts > @maxAttempts
|
||||
//
|
||||
// )
|
||||
// UPDATE remote_servers
|
||||
// SET is_dead = true
|
||||
// WHERE id IN (SELECT target_server_id FROM servers_to_kill)
|
||||
func (f failedOutboundRequestDo) KillServers(maxAttempts uint32) (err error) {
|
||||
var params []interface{}
|
||||
|
||||
var generateSQL strings.Builder
|
||||
params = append(params, maxAttempts)
|
||||
generateSQL.WriteString("WITH servers_to_kill AS ( SELECT target_server_id FROM failed_outbound_requests WHERE nr_of_attempts > ? ) UPDATE remote_servers SET is_dead = true WHERE id IN (SELECT target_server_id FROM servers_to_kill) ")
|
||||
|
||||
var executeSQL *gorm.DB
|
||||
executeSQL = f.UnderlyingDB().Exec(generateSQL.String(), params...) // ignore_security_alert
|
||||
err = executeSQL.Error
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (f failedOutboundRequestDo) Debug() IFailedOutboundRequestDo {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue