github.com/filecoin-project/bacalhau@v0.3.23-0.20230228154132-45c989550ace/pkg/compute/store/types.go (about) 1 package store 2 3 import ( 4 "context" 5 "fmt" 6 "time" 7 8 "github.com/filecoin-project/bacalhau/pkg/model" 9 ) 10 11 type Execution struct { 12 ID string 13 Shard model.JobShard 14 RequesterNodeID string 15 ResourceUsage model.ResourceUsageData 16 State ExecutionState 17 Version int 18 CreateTime time.Time 19 UpdateTime time.Time 20 LatestComment string 21 } 22 23 func NewExecution( 24 id string, 25 shard model.JobShard, 26 requesterNodeID string, 27 resourceUsage model.ResourceUsageData) *Execution { 28 return &Execution{ 29 ID: id, 30 Shard: shard, 31 RequesterNodeID: requesterNodeID, 32 ResourceUsage: resourceUsage, 33 State: ExecutionStateCreated, 34 Version: 1, 35 CreateTime: time.Now(), 36 UpdateTime: time.Now(), 37 } 38 } 39 40 // string returns a string representation of the execution 41 func (e Execution) String() string { 42 return fmt.Sprintf("{ID: %s, Shard: %s, State: %s}", e.ID, e.Shard.ID(), e.State) 43 } 44 45 type ExecutionHistory struct { 46 ExecutionID string 47 PreviousState ExecutionState 48 NewState ExecutionState 49 NewVersion int 50 Comment string 51 Time time.Time 52 } 53 54 // Summary of an execution that is used in logging and debugging. 55 type ExecutionSummary struct { 56 ExecutionID string `json:"ExecutionID"` 57 ShardID string `json:"ShardID"` 58 State string `json:"State"` 59 ResourceUsage model.ResourceUsageData `json:"ResourceUsage"` 60 } 61 62 // NewExecutionSummary generate a summary from an execution 63 func NewExecutionSummary(execution Execution) ExecutionSummary { 64 return ExecutionSummary{ 65 ExecutionID: execution.ID, 66 ShardID: execution.Shard.ID(), 67 State: execution.State.String(), 68 ResourceUsage: execution.ResourceUsage, 69 } 70 } 71 72 type UpdateExecutionStateRequest struct { 73 ExecutionID string 74 NewState ExecutionState 75 ExpectedState ExecutionState 76 ExpectedVersion int 77 Comment string 78 } 79 80 // ExecutionStore A metadata store of job executions handled by the current compute node 81 type ExecutionStore interface { 82 // GetExecution returns the execution for a given id 83 GetExecution(ctx context.Context, id string) (Execution, error) 84 // GetExecutions returns all the executions for a given shard 85 GetExecutions(ctx context.Context, sharedID string) ([]Execution, error) 86 // GetExecutionHistory returns the history of an execution 87 GetExecutionHistory(ctx context.Context, id string) ([]ExecutionHistory, error) 88 // CreateExecution creates a new execution for a given shard 89 CreateExecution(ctx context.Context, execution Execution) error 90 // UpdateExecutionState updates the execution state 91 UpdateExecutionState(ctx context.Context, request UpdateExecutionStateRequest) error 92 // DeleteExecution deletes an execution 93 DeleteExecution(ctx context.Context, id string) error 94 }