Refactoring per feedback.

- https://github.com/onepanelio/core/pull/226#discussion_r429046881
Removing helper methods that are not saving code.
- This also fixes k8s / db methods that were exposed from the package.
Instead, using an ArchiveWorkflowExecution function to achieve
the same functionality.
This commit is contained in:
Aleksandr Melnikov
2020-05-22 13:44:00 -07:00
parent 375ef146f3
commit 16b3f37b1d
2 changed files with 22 additions and 41 deletions

View File

@@ -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
}