oc-scheduler -> scheduling + logs
This commit is contained in:
@@ -99,9 +99,11 @@ func UpdateExecutionState(payload []byte, dt tools.DataType) {
|
||||
switch dt {
|
||||
case tools.BOOKING:
|
||||
if exec.BookingsState == nil {
|
||||
exec.BookingsState = map[string]bool{}
|
||||
exec.BookingsState = map[string]workflow_execution.BookingState{}
|
||||
}
|
||||
exec.BookingsState[data.ID] = true
|
||||
st := exec.BookingsState[data.ID]
|
||||
st.IsBooked = true
|
||||
exec.BookingsState[data.ID] = st
|
||||
case tools.PURCHASE_RESOURCE:
|
||||
if exec.PurchasesState == nil {
|
||||
exec.PurchasesState = map[string]bool{}
|
||||
@@ -111,7 +113,7 @@ func UpdateExecutionState(payload []byte, dt tools.DataType) {
|
||||
|
||||
allConfirmed := true
|
||||
for _, st := range exec.BookingsState {
|
||||
if !st {
|
||||
if !st.IsBooked {
|
||||
allConfirmed = false
|
||||
break
|
||||
}
|
||||
@@ -145,7 +147,7 @@ func confirmSessionOrder(executionsID string, adminReq *tools.APIRequest) {
|
||||
results, _, _ := order.NewAccessor(adminReq).Search(
|
||||
&dbs.Filters{And: map[string][]dbs.Filter{
|
||||
"executions_id": {{Operator: dbs.EQUAL.String(), Value: executionsID}},
|
||||
}}, "", true)
|
||||
}}, "", true, 0, 10000)
|
||||
for _, obj := range results {
|
||||
if o, ok := obj.(*order.Order); ok {
|
||||
o.IsDraft = false
|
||||
@@ -301,7 +303,7 @@ func Unschedule(executionID string, request *tools.APIRequest) error {
|
||||
|
||||
func RecoverDraft() {
|
||||
adminReq := &tools.APIRequest{Admin: true}
|
||||
results, _, _ := workflow_execution.NewAccessor(adminReq).Search(nil, "*", true)
|
||||
results, _, _ := workflow_execution.NewAccessor(adminReq).Search(nil, "*", true, 0, 10000)
|
||||
for _, obj := range results {
|
||||
exec, ok := obj.(*workflow_execution.WorkflowExecution)
|
||||
if !ok {
|
||||
@@ -350,6 +352,13 @@ func HandleWorkflowDone(resp tools.NATSResponse) {
|
||||
if evt.RealEnd != nil {
|
||||
exec.EndDate = evt.RealEnd
|
||||
}
|
||||
// All bookings are no longer reserved and are done
|
||||
if exec.BookingsState == nil {
|
||||
exec.BookingsState = map[string]workflow_execution.BookingState{}
|
||||
}
|
||||
for id := range exec.BookingsState {
|
||||
exec.BookingsState[id] = workflow_execution.BookingState{IsBooked: false, IsDone: true}
|
||||
}
|
||||
utils.GenericRawUpdateOne(exec, exec.GetID(), workflow_execution.NewAccessor(adminReq))
|
||||
for _, step := range evt.Steps {
|
||||
applyStepToBooking(step, adminReq)
|
||||
@@ -379,6 +388,21 @@ func HandleWorkflowStepDone(resp tools.NATSResponse) {
|
||||
bk.RealEndDate = evt.RealEnd
|
||||
}
|
||||
utils.GenericRawUpdateOne(bk, bk.GetID(), booking.NewAccessor(adminReq))
|
||||
|
||||
// Update BookingsState in the parent WorkflowExecution: resource released, step done
|
||||
execRes, _, execErr := workflow_execution.NewAccessor(adminReq).LoadOne(bk.ExecutionID)
|
||||
if execErr == nil && execRes != nil {
|
||||
exec := execRes.(*workflow_execution.WorkflowExecution)
|
||||
if exec.BookingsState == nil {
|
||||
exec.BookingsState = map[string]workflow_execution.BookingState{}
|
||||
}
|
||||
st := exec.BookingsState[evt.BookingID]
|
||||
st.IsBooked = false
|
||||
st.IsDone = true
|
||||
exec.BookingsState[evt.BookingID] = st
|
||||
utils.GenericRawUpdateOne(exec, exec.GetID(), workflow_execution.NewAccessor(adminReq))
|
||||
}
|
||||
|
||||
switch bk.State {
|
||||
case enum.SUCCESS, enum.FAILURE, enum.FORGOTTEN, enum.CANCELLED:
|
||||
self, err := oclib.GetMySelf()
|
||||
@@ -439,7 +463,7 @@ func scanStaleExecutions() error {
|
||||
res := oclib.NewRequest(oclib.LibDataEnum(oclib.WORKFLOW_EXECUTION), "", myself.GetID(), []string{}, nil).
|
||||
Search(&dbs.Filters{And: map[string][]dbs.Filter{
|
||||
"execution_date": {{Operator: dbs.LTE.String(), Value: primitive.NewDateTimeFromTime(deadline)}},
|
||||
}}, "", false)
|
||||
}}, "", false, 0, 10000)
|
||||
if res.Err != "" {
|
||||
return fmt.Errorf("stale execution search failed: %s", res.Err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user