From b2a6ac19cbb514ecc774a5b114204af6b00c3372 Mon Sep 17 00:00:00 2001 From: mr Date: Tue, 12 Nov 2024 12:17:30 +0100 Subject: [PATCH] state execution --- .../workflow_execution/workflow_execution.go | 18 +++++++++--------- .../workflow_execution_mongo_accessor.go | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/models/workflow_execution/workflow_execution.go b/models/workflow_execution/workflow_execution.go index b801773..2e23d6e 100644 --- a/models/workflow_execution/workflow_execution.go +++ b/models/workflow_execution/workflow_execution.go @@ -80,11 +80,11 @@ func (dma *WorkflowExecutions) Serialize() map[string]interface{} { * workflows generate their own executions */ type WorkflowExecution struct { - utils.AbstractObject // AbstractObject contains the basic fields of an object (id, name) - ExecDate *time.Time `json:"execution_date,omitempty" bson:"execution_date,omitempty" validate:"required"` // ExecDate is the execution date of the workflow, is required - EndDate *time.Time `json:"end_date,omitempty" bson:"end_date,omitempty"` // EndDate is the end date of the workflow - State int64 `json:"state" bson:"state" default:"0"` // State is the state of the workflow - WorkflowID string `json:"workflow_id" bson:"workflow_id,omitempty"` // WorkflowID is the ID of the workflow + utils.AbstractObject // AbstractObject contains the basic fields of an object (id, name) + ExecDate *time.Time `json:"execution_date,omitempty" bson:"execution_date,omitempty" validate:"required"` // ExecDate is the execution date of the workflow, is required + EndDate *time.Time `json:"end_date,omitempty" bson:"end_date,omitempty"` // EndDate is the end date of the workflow + State ScheduledType `json:"state" bson:"state" default:"0"` // State is the state of the workflow + WorkflowID string `json:"workflow_id" bson:"workflow_id,omitempty"` // WorkflowID is the ID of the workflow } func (wfa *WorkflowExecution) Equals(we *WorkflowExecution) bool { @@ -96,13 +96,13 @@ func (wfa *WorkflowExecution) ArgoStatusToState(status string) *WorkflowExecutio status = strings.ToLower(status) switch status { case "succeeded": // Succeeded - wfa.State = int64(SUCCESS.EnumIndex()) + wfa.State = SUCCESS case "pending": // Pending - wfa.State = int64(SCHEDULED.EnumIndex()) + wfa.State = SCHEDULED case "running": // Running - wfa.State = int64(STARTED.EnumIndex()) + wfa.State = STARTED default: // Failed - wfa.State = int64(FAILURE.EnumIndex()) + wfa.State = FAILURE } return wfa } diff --git a/models/workflow_execution/workflow_execution_mongo_accessor.go b/models/workflow_execution/workflow_execution_mongo_accessor.go index 6ad56d6..9d016b0 100644 --- a/models/workflow_execution/workflow_execution_mongo_accessor.go +++ b/models/workflow_execution/workflow_execution_mongo_accessor.go @@ -42,8 +42,8 @@ func (wfa *workflowExecutionMongoAccessor) LoadOne(id string) (utils.DBObject, i } res_mongo.Decode(&workflow) fmt.Println("workflow: ", workflow.State, time.Now().UTC().After(*workflow.ExecDate)) - if workflow.State == int64(SCHEDULED) && time.Now().UTC().After(*workflow.ExecDate) { - workflow.State = int64(FORGOTTEN) + if workflow.State == SCHEDULED && time.Now().UTC().After(*workflow.ExecDate) { + workflow.State = FORGOTTEN wfa.UpdateOne(&workflow, id) } return &workflow, 200, nil