feat: add deployment foundation and cross-device handoff
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
// Package state persists task metadata. It never executes application actions.
|
||||
package state
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrBusy = errors.New("host state is locked")
|
||||
ErrClosed = errors.New("session is closed")
|
||||
ErrPoisoned = errors.New("state write outcome uncertain; reopen and reconcile")
|
||||
ErrConflict = errors.New("operation identity or revision conflict")
|
||||
ErrUnresolved = errors.New("another operation requires completion or reconciliation")
|
||||
ErrTransition = errors.New("invalid operation transition")
|
||||
ErrNotFound = errors.New("operation not found")
|
||||
ErrCapacity = errors.New("operation history capacity exhausted")
|
||||
idPattern = regexp.MustCompile(`^[a-z][a-z0-9-]{0,47}$`)
|
||||
hashPattern = regexp.MustCompile(`^sha256:[a-f0-9]{64}$`)
|
||||
)
|
||||
|
||||
type Status string
|
||||
|
||||
const (
|
||||
Queued Status = "queued"
|
||||
Running Status = "running"
|
||||
Succeeded Status = "succeeded"
|
||||
FailedRecovered Status = "failed_recovered"
|
||||
NeedsAttention Status = "needs_attention"
|
||||
Unknown Status = "unknown"
|
||||
Cancelled Status = "cancelled"
|
||||
)
|
||||
|
||||
type Operation struct {
|
||||
ID string `json:"id"`
|
||||
PlanHash string `json:"planHash"`
|
||||
Status Status `json:"status"`
|
||||
Revision uint64 `json:"revision"`
|
||||
}
|
||||
|
||||
func (s Status) terminal() bool { return s == Succeeded || s == FailedRecovered || s == Cancelled }
|
||||
func (s Status) valid() bool {
|
||||
return s.terminal() || s == Queued || s == Running || s == NeedsAttention || s == Unknown
|
||||
}
|
||||
func allowed(from, to Status) bool {
|
||||
switch from {
|
||||
case Queued:
|
||||
return to == Running || to == Cancelled
|
||||
case Running:
|
||||
return to == Succeeded || to == FailedRecovered || to == NeedsAttention || to == Unknown
|
||||
case NeedsAttention, Unknown:
|
||||
return to == Succeeded || to == FailedRecovered
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user