Files
sablier/app/instance/instance.go
Alexis Couvreur 154bb5e7ed feat: pretty json
2022-11-02 23:15:06 -04:00

71 lines
1.5 KiB
Go

package instance
import log "github.com/sirupsen/logrus"
var Ready = "ready"
var NotReady = "not-ready"
var Unrecoverable = "unrecoverable"
type State struct {
Name string `json:"name"`
CurrentReplicas int `json:"currentReplicas"`
Status string `json:"status"`
Message string `json:"message,omitempty"`
}
func (instance State) IsReady() bool {
return instance.Status == Ready
}
func ErrorInstanceState(name string, err error) (State, error) {
log.Error(err.Error())
return State{
Name: name,
CurrentReplicas: 0,
Status: Unrecoverable,
Message: err.Error(),
}, err
}
func UnrecoverableInstanceState(name string, message string) (State, error) {
log.Warn(message)
return State{
Name: name,
CurrentReplicas: 0,
Status: Unrecoverable,
Message: message,
}, nil
}
func ReadyInstanceState(name string) (State, error) {
return State{
Name: name,
CurrentReplicas: 1,
Status: Ready,
}, nil
}
func ReadyInstanceStateOfReplicas(name string, replicas int) (State, error) {
return State{
Name: name,
CurrentReplicas: replicas,
Status: Ready,
}, nil
}
func NotReadyInstanceState(name string) (State, error) {
return State{
Name: name,
CurrentReplicas: 0,
Status: NotReady,
}, nil
}
func NotReadyInstanceStateOfReplicas(name string, replicas int) (State, error) {
return State{
Name: name,
CurrentReplicas: replicas,
Status: NotReady,
}, nil
}