github.com/kyma-incubator/compass/components/director@v0.0.0-20230623144113-d764f56ff805/internal/model/operation.go (about) 1 package model 2 3 import ( 4 "encoding/json" 5 "time" 6 ) 7 8 // OperationStatus defines operation status 9 type OperationStatus string 10 11 const ( 12 // OperationStatusScheduled scheduled operation status 13 OperationStatusScheduled OperationStatus = "SCHEDULED" 14 // OperationStatusInProgress in progress operation status 15 OperationStatusInProgress OperationStatus = "IN_PROGRESS" 16 // OperationStatusCompleted completed operation status 17 OperationStatusCompleted OperationStatus = "COMPLETED" 18 // OperationStatusFailed failed operation status 19 OperationStatusFailed OperationStatus = "FAILED" 20 ) 21 22 // Operation represents an Operation 23 type Operation struct { 24 ID string 25 OpType string 26 Status OperationStatus 27 Data json.RawMessage 28 Error json.RawMessage 29 Priority int 30 CreatedAt *time.Time 31 FinishedAt *time.Time 32 } 33 34 // OperationInput represents an OperationInput 35 type OperationInput struct { 36 OpType string 37 Status OperationStatus 38 Data json.RawMessage 39 Error json.RawMessage 40 Priority int 41 CreatedAt *time.Time 42 FinishedAt *time.Time 43 } 44 45 // ToOperation converts OperationInput to Operation 46 func (i *OperationInput) ToOperation(id string) *Operation { 47 if i == nil { 48 return nil 49 } 50 51 return &Operation{ 52 ID: id, 53 OpType: i.OpType, 54 Status: i.Status, 55 Data: i.Data, 56 Error: i.Error, 57 Priority: i.Priority, 58 CreatedAt: i.CreatedAt, 59 FinishedAt: i.FinishedAt, 60 } 61 }