Refactoring DB queries related to archiving.

- Using Squirrel RunWith instead of ToSql.
This commit is contained in:
Aleksandr Melnikov
2020-05-21 22:19:26 -07:00
parent e6d30407c9
commit 1a9ce9870d
2 changed files with 45 additions and 6 deletions

View File

@@ -514,12 +514,18 @@ func (c *Client) TerminateCronWorkflow(namespace, uid string) (err error) {
if err != nil { if err != nil {
return err return err
} }
tx, err := c.DB.Begin()
query, args, err := sb.Delete("workflow_executions").Where(sq.Eq{ if err != nil {
return err
}
defer tx.Rollback()
_, err = sb.Update("workflow_executions").
Set("is_archived", true).
Where(sq.Eq{
"cron_workflow_id": cronWorkflow.ID, "cron_workflow_id": cronWorkflow.ID,
}).ToSql() }).RunWith(tx).Exec()
if _, err := c.DB.Exec(query, args...); err != nil { if err != nil {
return err return err
} }
@@ -707,7 +713,24 @@ func (c *Client) DeleteCronWorkflowDb(namespace, uid string) error {
return nil return nil
} }
func (c *Client) DeleteCronWorkflow(namespace, uid string) error { func (c *Client) ArchiveCronWorkflowDB(namespace, uid string) error {
tx, err := c.DB.Begin()
if err != nil {
return err
}
defer tx.Rollback()
_, err = sb.Update("cron_workflows").
Set("is_archived", true).
Where(sq.Eq{
"uid": uid,
"namespace": namespace,
}).RunWith(tx).Exec()
if err != nil {
return err
}
return nil
}
err := c.ArgoprojV1alpha1().CronWorkflows(namespace).Delete(uid, nil) err := c.ArgoprojV1alpha1().CronWorkflows(namespace).Delete(uid, nil)
if err != nil { if err != nil {
if strings.Contains(err.Error(), "not found") { if strings.Contains(err.Error(), "not found") {

View File

@@ -1488,3 +1488,19 @@ func (c *Client) DeleteWorkflowExecutionDb(workflowUid string) error {
} }
return nil 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
}
return nil
}