Build complete event
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"oc-monitord/conf"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
||||
"cloud.o-forge.io/core/oc-lib/models/common/models"
|
||||
@@ -106,7 +107,7 @@ type Template struct {
|
||||
Resource ServiceResource `yaml:"resource,omitempty"`
|
||||
}
|
||||
|
||||
func (template *Template) CreateEventContainer(exec *workflow_execution.WorkflowExecution, nt *resources.NativeTool, dag *Dag) {
|
||||
func (template *Template) CreateEventContainer(execution *workflow_execution.WorkflowExecution, nt *resources.NativeTool, dag *Dag) {
|
||||
container := Container{Image: "natsio/nats-box"}
|
||||
container.Command = []string{"sh", "-c"} // all is bash
|
||||
|
||||
@@ -122,9 +123,29 @@ func (template *Template) CreateEventContainer(exec *workflow_execution.Workflow
|
||||
return
|
||||
}
|
||||
if event.WorkflowResourceID != "" {
|
||||
container.Args = append(container.Args, "nats pub --server "+conf.GetConfig().NatsURL+":4222 "+tools.WORKFLOW_EVENT.GenerateKey()+" '{\"workflow_id\":\""+event.WorkflowResourceID+"\"}'")
|
||||
container.Args = []string{strings.Join(container.Args, " ")}
|
||||
template.Container = container
|
||||
event.Payload = event.Input
|
||||
event.Input = ""
|
||||
if b, err := json.Marshal(event); err == nil {
|
||||
payload, err := json.Marshal(&tools.NATSResponse{
|
||||
FromApp: "oc-monitord",
|
||||
Datatype: tools.NATIVE_TOOL,
|
||||
Method: int(tools.WORKFLOW_EVENT),
|
||||
Payload: b,
|
||||
})
|
||||
if err == nil {
|
||||
cmd := exec.Command(
|
||||
"nats",
|
||||
"pub",
|
||||
"--server", conf.GetConfig().NatsURL+":4222",
|
||||
tools.WORKFLOW_EVENT.GenerateKey(),
|
||||
string(payload),
|
||||
)
|
||||
for _, args := range cmd.Args {
|
||||
container.Args = append(container.Args, args)
|
||||
}
|
||||
template.Container = container
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user