mirror of
https://github.com/onepanelio/onepanel.git
synced 2025-10-27 23:31:27 +08:00
DRY Principle - Simplified if-else for insert SQL.
This commit is contained in:
@@ -378,32 +378,22 @@ func (c *Client) AddWorkflowExecutionStatistic(namespace, name string, workflowT
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer tx.Rollback()
|
defer tx.Rollback()
|
||||||
|
|
||||||
|
insertMap := sq.Eq{
|
||||||
|
"workflow_template_id": workflowTemplateID,
|
||||||
|
"name": name,
|
||||||
|
"namespace": namespace,
|
||||||
|
"created_at": createdAt.UTC(),
|
||||||
|
}
|
||||||
|
|
||||||
if workflowOutcomeIsSuccess {
|
if workflowOutcomeIsSuccess {
|
||||||
_, err := sb.Insert("workflow_executions").
|
insertMap["finished_at"] = time.Now().UTC()
|
||||||
SetMap(sq.Eq{
|
|
||||||
"workflow_template_id": workflowTemplateID,
|
|
||||||
"name": name,
|
|
||||||
"namespace": namespace,
|
|
||||||
"created_at": createdAt.UTC(),
|
|
||||||
"finished_at": time.Now().UTC(),
|
|
||||||
}).RunWith(tx).Exec()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = tx.Commit()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
} else {
|
} else {
|
||||||
_, err := sb.Insert("workflow_executions").
|
insertMap["failed_at"] = time.Now().UTC()
|
||||||
SetMap(sq.Eq{
|
}
|
||||||
"workflow_template_id": workflowTemplateID,
|
|
||||||
"name": name,
|
_, err = sb.Insert("workflow_executions").
|
||||||
"namespace": namespace,
|
SetMap(insertMap).RunWith(tx).Exec()
|
||||||
"created_at": createdAt.UTC(),
|
|
||||||
"failed_at": time.Now().UTC(),
|
|
||||||
}).RunWith(tx).Exec()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -413,7 +403,6 @@ func (c *Client) AddWorkflowExecutionStatistic(namespace, name string, workflowT
|
|||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Client) GetWorkflowExecution(namespace, name string) (workflow *WorkflowExecution, err error) {
|
func (c *Client) GetWorkflowExecution(namespace, name string) (workflow *WorkflowExecution, err error) {
|
||||||
wf, err := c.ArgoprojV1alpha1().Workflows(namespace).Get(name, metav1.GetOptions{})
|
wf, err := c.ArgoprojV1alpha1().Workflows(namespace).Get(name, metav1.GetOptions{})
|
||||||
|
|||||||
Reference in New Issue
Block a user