From 62c8f5dcb283670191bbe3b27e93d36b1a8652b3 Mon Sep 17 00:00:00 2001 From: Aleksandr Melnikov Date: Thu, 14 May 2020 17:13:44 -0700 Subject: [PATCH] Adding support for terminated workflow executions. - When terminating, adding started_at and finished_at timestamps Updated workflow_template.proto to return the count of terminated executions. - Updating supporting code --- api/workflow_template.proto | 1 + pkg/workflow_execution.go | 19 +++++++++++++++++++ server/workflow_template_server.go | 1 + 3 files changed, 21 insertions(+) diff --git a/api/workflow_template.proto b/api/workflow_template.proto index 27c57c3..7aac882 100644 --- a/api/workflow_template.proto +++ b/api/workflow_template.proto @@ -126,6 +126,7 @@ message WorkflowExecutionStatisticReport { int32 running = 3; int32 completed = 4; int32 failed = 5; + int32 terminated = 6; } message CronWorkflowStatisticsReport { diff --git a/pkg/workflow_execution.go b/pkg/workflow_execution.go index fd458a5..12a3666 100644 --- a/pkg/workflow_execution.go +++ b/pkg/workflow_execution.go @@ -944,6 +944,24 @@ func (c *Client) SuspendWorkflowExecution(namespace, uid string) (err error) { } func (c *Client) TerminateWorkflowExecution(namespace, uid string) (err error) { + query, args, err := sb.Update("workflow_executions"). + Set("phase", "Terminated"). + Set("started_at", time.Time.UTC(time.Now())). + Set("finished_at", time.Time.UTC(time.Now())). + Where(sq.Eq{ + "uid": uid, + "namespace": namespace, + }). + ToSql() + + if err != nil { + return err + } + + if _, err := c.DB.Exec(query, args...); err != nil { + return err + } + err = argoutil.TerminateWorkflow(c.ArgoprojV1alpha1().Workflows(namespace), uid) return @@ -1242,6 +1260,7 @@ func (c *Client) GetWorkflowExecutionStatisticsForTemplates(workflowTemplates .. COUNT(*) FILTER (WHERE finished_at IS NULL AND (phase = 'Running' OR phase = 'Pending')) running, COUNT(*) FILTER (WHERE finished_at IS NOT NULL AND phase = 'Succeeded') completed, COUNT(*) FILTER (WHERE finished_at IS NOT NULL AND (phase = 'Failed' OR phase = 'Error')) failed, + COUNT(*) FILTER (WHERE phase = 'Terminated') terminated, COUNT(*) total` query, args, err := sb.Select(statsSelect). diff --git a/server/workflow_template_server.go b/server/workflow_template_server.go index d4203a3..bcbd173 100644 --- a/server/workflow_template_server.go +++ b/server/workflow_template_server.go @@ -38,6 +38,7 @@ func apiWorkflowTemplate(wft *v1.WorkflowTemplate) *api.WorkflowTemplate { Running: wft.WorkflowExecutionStatisticReport.Running, Completed: wft.WorkflowExecutionStatisticReport.Completed, Failed: wft.WorkflowExecutionStatisticReport.Failed, + Terminated: wft.WorkflowExecutionStatisticReport.Terminated, } }