-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworkflows.go
98 lines (82 loc) · 2.63 KB
/
workflows.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package main
import (
"encoding/json"
"errors"
"net/http"
"os"
"time"
"github.com/bcc-code/bcc-media-flows/services/vidispine/vscommon"
"github.com/bcc-code/bcc-media-flows/workflows/export"
"github.com/gin-gonic/gin"
"go.temporal.io/api/history/v1"
"go.temporal.io/api/workflowservice/v1"
)
type WorkflowListParams struct {
WorkflowList []WorkflowDetails
WorkflowStatuses map[string]string
}
type WorkflowDetails struct {
VxID string
Name string
Status string
WorkflowID string
Start string
}
func (s *TriggerServer) listGET(ctx *gin.Context) {
var workflowList []WorkflowDetails
workflows, err := s.wfClient.ListWorkflow(ctx, &workflowservice.ListWorkflowExecutionsRequest{
Query: "WorkflowType = 'VXExport'",
})
if err != nil {
renderErrorPage(ctx, http.StatusInternalServerError, err)
return
}
for i := 0; i < len(workflows.Executions); i++ {
res, err := s.wfClient.WorkflowService().GetWorkflowExecutionHistory(ctx, &workflowservice.GetWorkflowExecutionHistoryRequest{
Execution: workflows.Executions[i].GetExecution(),
Namespace: os.Getenv("TEMPORAL_NAMESPACE"),
})
if err != nil {
renderErrorPage(ctx, http.StatusInternalServerError, err)
return
}
attributes, ok := res.History.Events[0].Attributes.(*history.HistoryEvent_WorkflowExecutionStartedEventAttributes)
if !ok {
renderErrorPage(ctx, 500, errors.New("unexpected attribute type on first workflow event. Was not HistoryEvent_WorkflowExecutionStartedEventAttributes"))
break
}
data := export.VXExportParams{}
err = json.Unmarshal(attributes.WorkflowExecutionStartedEventAttributes.Input.Payloads[0].Data, &data)
if err != nil {
renderErrorPage(ctx, http.StatusInternalServerError, err)
return
}
meta, err := s.vidispine.GetMetadata(data.VXID)
if err != nil {
renderErrorPage(ctx, http.StatusInternalServerError, err)
return
}
name := meta.Get(vscommon.FieldTitle, "")
loc, _ := time.LoadLocation("Europe/Oslo")
startTime := workflows.Executions[i].StartTime.In(loc).Format("Mon, 02 Jan 2006 15:04:05 MST")
workflowList = append(workflowList, WorkflowDetails{
VxID: data.VXID,
Name: name,
Status: workflows.Executions[i].GetStatus().String(),
WorkflowID: workflows.Executions[i].Execution.WorkflowId,
Start: startTime,
})
}
workflowStatuses := map[string]string{
"Running": "blue",
"Timed out": "yellow",
"Completed": "green",
"Failed": "red",
"Canceled": "yellow",
"Terminated": "red",
}
ctx.HTML(http.StatusOK, "list.gohtml", WorkflowListParams{
WorkflowList: workflowList,
WorkflowStatuses: workflowStatuses,
})
}