github.com/filecoin-project/bacalhau@v0.3.23-0.20230228154132-45c989550ace/pkg/model/v1beta1/jobeventtype.go (about) 1 package v1beta1 2 3 import ( 4 "fmt" 5 ) 6 7 //go:generate stringer -type=JobEventType --trimprefix=JobEvent 8 type JobEventType int 9 10 const ( 11 jobEventUnknown JobEventType = iota // must be first 12 13 // Job has been created by client and is communicating with requestor node 14 JobEventInitialSubmission 15 16 // Job has been created on the requestor node 17 JobEventCreated 18 19 // the concurrency or other mutable properties of the job were 20 // changed by the client 21 JobEventDealUpdated 22 23 // a compute node bid on a job 24 JobEventBid 25 26 // a requester node accepted for rejected a job bid 27 JobEventBidAccepted 28 JobEventBidRejected 29 30 // a compute node canceled a job bid 31 JobEventBidCancelled 32 33 // TODO: what if a requester node accepts a bid 34 // and the compute node takes too long to start running it? 35 // JobEventBidRevoked 36 37 // a compute node progressed with running a job 38 // this is called periodically for running jobs 39 // to give the client confidence the job is still running 40 // this is like a heartbeat for running jobs 41 JobEventRunning 42 43 // a compute node had an error running a job 44 JobEventComputeError 45 46 // a compute node completed running a job 47 JobEventResultsProposed 48 49 // a Requester node accepted the results from a node for a job 50 JobEventResultsAccepted 51 52 // a Requester node rejected the results from a node for a job 53 JobEventResultsRejected 54 55 // once the results have been accepted or rejected 56 // the compute node will publish them and issue this event 57 JobEventResultsPublished 58 59 // a requester node declared an error running a job 60 JobEventError 61 62 // the requester node gives a compute node permission 63 // to forget about the job and free any resources it might 64 // currently be reserving - this can happen if a compute node 65 // bids when a job has completed - if the compute node does 66 // not hear back it will be stuck in reserving the resources for the job 67 JobEventInvalidRequest 68 69 jobEventDone // must be last 70 ) 71 72 // IsTerminal returns true if the given event type signals the end of the 73 // lifecycle of a job. After this, all nodes can safely ignore the job. 74 func (je JobEventType) IsTerminal() bool { 75 return je == JobEventError || je == JobEventResultsPublished 76 } 77 78 // IsIgnorable returns true if given event type signals that a node can safely 79 // ignore the rest of the job's lifecycle. This is the case for events caused 80 // by a node's bid being rejected. 81 func (je JobEventType) IsIgnorable() bool { 82 return je.IsTerminal() || je == JobEventComputeError || je == JobEventBidRejected || je == JobEventInvalidRequest 83 } 84 85 func ParseJobEventType(str string) (JobEventType, error) { 86 for typ := jobEventUnknown + 1; typ < jobEventDone; typ++ { 87 if equal(typ.String(), str) { 88 return typ, nil 89 } 90 } 91 92 return jobEventUnknown, fmt.Errorf( 93 "executor: unknown job event type '%s'", str) 94 } 95 96 func JobEventTypes() []JobEventType { 97 var res []JobEventType 98 for typ := jobEventUnknown + 1; typ < jobEventDone; typ++ { 99 res = append(res, typ) 100 } 101 102 return res 103 } 104 105 func (je JobEventType) MarshalText() ([]byte, error) { 106 return []byte(je.String()), nil 107 } 108 109 func (je *JobEventType) UnmarshalText(text []byte) (err error) { 110 name := string(text) 111 *je, err = ParseJobEventType(name) 112 return 113 }