diff --git a/pkg/workflow_execution.go b/pkg/workflow_execution.go index 990b4f0..67cd8b9 100644 --- a/pkg/workflow_execution.go +++ b/pkg/workflow_execution.go @@ -173,6 +173,26 @@ func (c *Client) injectAutomatedFields(namespace string, wf *wfv1.Workflow, opts return } +func (c *Client) ArchiveWorkflowExecution(namespace, uid string) error { + _, err := sb.Update("workflow_executions").Set("is_archived", true).Where(sq.Eq{ + "uid": uid, + "namespace": namespace, + }).RunWith(c.DB).Exec() + if err != nil { + return err + } + + err = c.ArgoprojV1alpha1().Workflows(namespace).Delete(uid, nil) + if err != nil { + if strings.Contains(err.Error(), "not found") { + return nil + } + return err + } + + return nil +} + /* Name is == to UID, no user friendly name. Workflow execution name == uid, example: name = my-friendly-wf-name-8skjz, uid = my-friendly-wf-name-8skjz @@ -1466,33 +1486,3 @@ func (c *Client) getWorkflowExecutionAndTemplate(namespace string, uid string) ( return } - -func (c *Client) DeleteWorkflowExecutionK8S(namespace, uid string) error { - err := c.ArgoprojV1alpha1().Workflows(namespace).Delete(uid, nil) - if err != nil { - if strings.Contains(err.Error(), "not found") { - return nil - } - return err - } - return nil -} - -func (c *Client) ArchiveWorkflowExecutionDB(namespace, uid string) error { - tx, err := c.DB.Begin() - if err != nil { - return err - } - defer tx.Rollback() - _, err = sb.Update("workflow_executions").Set("is_archived", true).Where(sq.Eq{ - "uid": uid, - "namespace": namespace, - }).RunWith(tx).Exec() - if err != nil { - return err - } - if err := tx.Commit(); err != nil { - return err - } - return nil -} diff --git a/pkg/workflow_template.go b/pkg/workflow_template.go index 0a566da..63e7a33 100644 --- a/pkg/workflow_template.go +++ b/pkg/workflow_template.go @@ -678,22 +678,13 @@ func (c *Client) ArchiveWorkflowTemplate(namespace, uid string) (archived bool, break } for _, wf := range wfs { - err = c.DeleteWorkflowExecutionK8S(namespace, wf.UID) + err = c.ArchiveWorkflowExecution(namespace, wf.UID) if err != nil { log.WithFields(log.Fields{ "Namespace": namespace, "UID": uid, "Error": err.Error(), - }).Error("Delete Workflow Execution k8s failed.") - return false, util.NewUserError(codes.Unknown, "Unable to archive workflow template.") - } - err = c.ArchiveWorkflowExecutionDB(namespace, wf.UID) - if err != nil { - log.WithFields(log.Fields{ - "Namespace": namespace, - "UID": uid, - "Error": err.Error(), - }).Error("Delete Workflow Execution DB failed.") + }).Error("Archive Workflow Execution.") return false, util.NewUserError(codes.Unknown, "Unable to archive workflow template.") } }