update: cron workflows to use new labels

This commit is contained in:
Andrey Melnikov
2020-08-09 16:15:05 -07:00
parent 55eeb90e2a
commit 8586639a6c
7 changed files with 28 additions and 261 deletions

View File

@@ -565,29 +565,18 @@ func (c *Client) createWorkflowExecutionDB(namespace string, workflowExecution *
}
func (c *Client) FinishWorkflowExecutionStatisticViaExitHandler(namespace, name string, workflowTemplateID int64, phase wfv1.NodePhase, startedAt time.Time) (err error) {
tx, err := c.DB.Begin()
if err != nil {
return err
}
defer tx.Rollback()
updateMap := sq.Eq{
"started_at": startedAt.UTC(),
"name": name,
"namespace": namespace,
"finished_at": time.Now().UTC(),
"phase": phase,
}
_, err = sb.Update("workflow_executions").
SetMap(updateMap).Where(sq.Eq{"name": name}).RunWith(tx).Exec()
if err != nil {
return err
}
err = tx.Commit()
if err != nil {
return err
}
SetMap(sq.Eq{
"started_at": startedAt.UTC(),
"name": name,
"namespace": namespace,
"finished_at": time.Now().UTC(),
"phase": phase,
}).
Where(sq.Eq{"name": name}).
RunWith(c.DB).
Exec()
return err
}
@@ -609,12 +598,6 @@ func (c *Client) CronStartWorkflowExecutionStatisticInsert(namespace, uid string
return err
}
tx, err := c.DB.Begin()
if err != nil {
return err
}
defer tx.Rollback()
parametersJSON, err := cronWorkflow.GetParametersFromWorkflowSpecJSON()
if err != nil {
return err
@@ -631,26 +614,16 @@ func (c *Client) CronStartWorkflowExecutionStatisticInsert(namespace, uid string
"started_at": time.Now().UTC(),
"cron_workflow_id": cronWorkflow.ID,
"parameters": string(parametersJSON),
"labels": cronWorkflow.Labels,
}).
Suffix("RETURNING id").
RunWith(tx).
RunWith(c.DB).
QueryRow().
Scan(&workflowExecutionID)
if err != nil {
return err
}
cronLabels, err := c.GetDBLabelsMapped(TypeCronWorkflow, cronWorkflow.ID)
if err != nil {
return err
}
labelsMapped := cronLabels[cronWorkflow.ID]
if _, err := c.InsertLabelsRunner(tx, TypeWorkflowExecution, workflowExecutionID, labelsMapped); err != nil {
return err
}
err = tx.Commit()
return err
}