neooclib
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
package daemons
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"cloud.o-forge.io/core/oc-lib/models/common/enum"
|
||||
"cloud.o-forge.io/core/oc-lib/models/workflow_execution"
|
||||
"cloud.o-forge.io/core/oc-lib/tools"
|
||||
)
|
||||
|
||||
// emitExecStateUpdate loads the execution, sets its state and emits a
|
||||
// CREATE_RESOURCE NATS event so oc-scheduler applies the change and fires
|
||||
// NotifyChange for the WebSocket streams.
|
||||
// Direct UpdateOne calls are replaced by this function so oc-scheduler remains
|
||||
// the single writer for WorkflowExecution.
|
||||
func emitExecStateUpdate(execID string, state enum.BookingStatus) {
|
||||
adminReq := &tools.APIRequest{Admin: true}
|
||||
res, _, err := workflow_execution.NewAccessor(adminReq).LoadOne(execID)
|
||||
if err != nil || res == nil {
|
||||
return
|
||||
}
|
||||
exec := res.(*workflow_execution.WorkflowExecution)
|
||||
exec.State = state
|
||||
payload, marshalErr := json.Marshal(exec)
|
||||
if marshalErr != nil {
|
||||
return
|
||||
}
|
||||
tools.NewNATSCaller().SetNATSPub(tools.CREATE_RESOURCE, tools.NATSResponse{
|
||||
FromApp: "oc-schedulerd",
|
||||
Datatype: tools.WORKFLOW_EXECUTION,
|
||||
Method: int(tools.CREATE_RESOURCE),
|
||||
Payload: payload,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user