diff --git a/models/workflow_execution/workflow_execution.go b/models/workflow_execution/workflow_execution.go index 354f686..e273c2c 100755 --- a/models/workflow_execution/workflow_execution.go +++ b/models/workflow_execution/workflow_execution.go @@ -17,6 +17,17 @@ import ( "go.mongodb.org/mongo-driver/bson/primitive" ) +// BookingState tracks the reservation and completion status of a single booking +// within a workflow execution. +// - IsBooked: true while the resource is actively reserved (set on WORKFLOW_STARTED_EVENT, +// cleared on WORKFLOW_STEP_DONE_EVENT / WORKFLOW_DONE_EVENT). +// - IsDone: true once the booking has been confirmed by the remote peer (CONSIDERS_EVENT) +// or completed (WORKFLOW_STEP_DONE_EVENT / WORKFLOW_DONE_EVENT). +type BookingState struct { + IsBooked bool `json:"is_booked" bson:"is_booked"` + IsDone bool `json:"is_done" bson:"is_done"` +} + /* * WorkflowExecution is a struct that represents a list of workflow executions * Warning: No user can write (del, post, put) a workflow execution, it is only used by the system @@ -33,8 +44,8 @@ type WorkflowExecution struct { State enum.BookingStatus `json:"state" bson:"state" default:"0"` // TEMPORARY TODO DEFAULT 1 -> 0 State is the state of the workflow WorkflowID string `json:"workflow_id" bson:"workflow_id,omitempty"` // WorkflowID is the ID of the workflow - BookingsState map[string]bool `json:"bookings_state" bson:"bookings_state,omitempty"` // WorkflowID is the ID of the workflow - PurchasesState map[string]bool `json:"purchases_state" bson:"purchases_state,omitempty"` // WorkflowID is the ID of the workflow + BookingsState map[string]BookingState `json:"bookings_state" bson:"bookings_state,omitempty"` // booking_id → reservation+completion status + PurchasesState map[string]bool `json:"purchases_state" bson:"purchases_state,omitempty"` // purchase_id → confirmed SelectedInstances workflow.ConfigItem `json:"selected_instances"` SelectedPartnerships workflow.ConfigItem `json:"selected_partnerships"` @@ -189,9 +200,9 @@ func (d *WorkflowExecution) Book(executionsID string, wfID string, priceds map[t booking = append(booking, d.bookEach(executionsID, wfID, tools.DATA_RESOURCE, priceds[tools.DATA_RESOURCE])...) for _, p := range booking { if d.BookingsState == nil { - d.BookingsState = map[string]bool{} + d.BookingsState = map[string]BookingState{} } - d.BookingsState[p.GetID()] = false + d.BookingsState[p.GetID()] = BookingState{} } return booking }