forked from tangled.org/core
this repo has no description
1package models 2 3import ( 4 "fmt" 5 "regexp" 6 "slices" 7 8 "tangled.sh/tangled.sh/core/api/tangled" 9 10 "github.com/bluesky-social/indigo/atproto/syntax" 11) 12 13var ( 14 re = regexp.MustCompile(`[^a-zA-Z0-9_.-]`) 15) 16 17type PipelineId struct { 18 Knot string 19 Rkey string 20} 21 22func (p *PipelineId) AtUri() syntax.ATURI { 23 return syntax.ATURI(fmt.Sprintf("at://did:web:%s/%s/%s", p.Knot, tangled.PipelineNSID, p.Rkey)) 24} 25 26type WorkflowId struct { 27 PipelineId 28 Name string 29} 30 31func (wid WorkflowId) String() string { 32 return fmt.Sprintf("%s-%s-%s", normalize(wid.Knot), wid.Rkey, normalize(wid.Name)) 33} 34 35func normalize(name string) string { 36 normalized := re.ReplaceAllString(name, "-") 37 return normalized 38} 39 40type StatusKind string 41 42var ( 43 StatusKindPending StatusKind = "pending" 44 StatusKindRunning StatusKind = "running" 45 StatusKindFailed StatusKind = "failed" 46 StatusKindTimeout StatusKind = "timeout" 47 StatusKindCancelled StatusKind = "cancelled" 48 StatusKindSuccess StatusKind = "success" 49 50 StartStates [2]StatusKind = [2]StatusKind{ 51 StatusKindPending, 52 StatusKindRunning, 53 } 54 FinishStates [4]StatusKind = [4]StatusKind{ 55 StatusKindCancelled, 56 StatusKindFailed, 57 StatusKindSuccess, 58 StatusKindTimeout, 59 } 60) 61 62func (s StatusKind) String() string { 63 return string(s) 64} 65 66func (s StatusKind) IsStart() bool { 67 return slices.Contains(StartStates[:], s) 68} 69 70func (s StatusKind) IsFinish() bool { 71 return slices.Contains(FinishStates[:], s) 72}