add history

This commit is contained in:
mr
2024-10-02 11:35:22 +02:00
parent 3c1a84011e
commit 93903b4938
23 changed files with 140 additions and 63 deletions

View File

@@ -84,7 +84,7 @@ func (d *Workflow) GetName() string {
func (d *Workflow) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
data := New() // Create a new instance of the accessor
data.Init(utils.WORKFLOW, caller) // Initialize the accessor with the WORKFLOW model type
data.Init(tools.WORKFLOW, caller) // Initialize the accessor with the WORKFLOW model type
return data
}

View File

@@ -0,0 +1,34 @@
package workflow
import (
"cloud.o-forge.io/core/oc-lib/models/utils"
"cloud.o-forge.io/core/oc-lib/tools"
"github.com/google/uuid"
)
type WorkflowHistory struct{ Workflow }
func (d *WorkflowHistory) GetAccessor(caller *tools.HTTPCaller) utils.Accessor {
data := New() // Create a new instance of the accessor
data.Init(tools.WORKSPACE_HISTORY, caller) // Initialize the accessor with the WORKSPACE model type
return data
}
func (r *WorkflowHistory) GenerateID() {
r.UUID = uuid.New().String()
}
// Workspace is a struct that represents a workspace
type workflowHistoryMongoAccessor struct {
workflowMongoAccessor // AbstractAccessor contains the basic fields of an accessor (model, caller)
}
// New creates a new instance of the workspaceMongoAccessor
func NewHistory() *workflowHistoryMongoAccessor {
return &workflowHistoryMongoAccessor{}
}
func (r *workflowHistoryMongoAccessor) MapFromWorkflow(w *Workflow) *WorkflowHistory {
wh := &WorkflowHistory{Workflow: *w}
wh.GenerateID()
return wh
}

View File

@@ -175,6 +175,8 @@ func (wfa *workflowMongoAccessor) share(realData *Workflow, delete bool, caller
continue
}
if delete { // if the workflow is deleted, share the deletion
history := NewHistory()
history.StoreOne(history.MapFromWorkflow(res.(*Workflow)))
_, err = paccess.LaunchPeerExecution(p, res.GetID(), tools.WORKFLOW, tools.DELETE, map[string]interface{}{}, caller)
} else { // if the workflow is updated, share the update
_, err = paccess.LaunchPeerExecution(p, res.GetID(), tools.WORKFLOW, tools.PUT, res.Serialize(), caller)
@@ -196,9 +198,9 @@ func (wfa *workflowMongoAccessor) execution(id string, realData *Workflow, delet
mongo.MONGOService.DeleteMultiple(map[string]interface{}{
"state": 1, // only delete the scheduled executions only scheduled if executions are in progress or ended, they should not be deleted for registration
"workflow_id": id,
}, utils.WORKFLOW_EXECUTION.String())
}, tools.WORKFLOW_EXECUTION.String())
err := wfa.book(id, realData, []*workflow_execution.WorkflowExecution{}) // delete the booking of the workflow on the peers
nats.SetNATSPub(utils.WORKFLOW.String(), tools.REMOVE, realData) // send the deletion to the nats
nats.SetNATSPub(tools.WORKFLOW.String(), tools.REMOVE, realData) // send the deletion to the nats
if err != nil {
return 409, err
}
@@ -224,7 +226,7 @@ func (wfa *workflowMongoAccessor) execution(id string, realData *Workflow, delet
return code, err
}
}
nats.SetNATSPub(utils.WORKFLOW.String(), tools.CREATE, realData) // send the creation to the nats
nats.SetNATSPub(tools.WORKFLOW.String(), tools.CREATE, realData) // send the creation to the nats
} else {
return 422, err
}