linstrom/storage-new/models/FailedOutboundRequests.go
mstar 7ac4c628b8
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
2025-07-03 13:57:30 +02:00

32 lines
1.4 KiB
Go

package models
import "time"
// Stores an outbound request that hasn't successfully resolved yet
type FailedOutboundRequest struct {
Id uint64 `gorm:"primarykey"`
RawData []byte // The body data of the request
Target string // The url to send the data to (via post)
FirstAttempt time.Time // When the first attempt was started
LastAttempt time.Time // When the latest attempt was started
ActingUser *User // The user on who's behalf the request is being performed
ActingUserId string // Id of the acting user
NrOfAttempts uint32 // How often the request was attempted already
LastFailureReason string // The reason why the last attempt failed (actually a FailedOutboundRequestReason)
TargetServer *RemoteServer // The remote server being targeted. Included to determine if a request still has a chance of success
TargetServerId uint // Id of the target remote server
}
type IFailedOutboundRequest interface {
// 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)
KillServers(maxAttempts uint32) error
}