mirror of
https://github.com/onepanelio/onepanel.git
synced 2025-10-17 19:20:36 +08:00
Added insert statements for workflow_executions table.
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
sq "github.com/Masterminds/squirrel"
|
||||||
"github.com/ghodss/yaml"
|
"github.com/ghodss/yaml"
|
||||||
"github.com/onepanelio/core/pkg/util/label"
|
"github.com/onepanelio/core/pkg/util/label"
|
||||||
"io"
|
"io"
|
||||||
@@ -346,6 +347,49 @@ func (c *Client) CreateWorkflowExecution(namespace string, workflow *WorkflowExe
|
|||||||
return workflow, nil
|
return workflow, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Client) AddWorkflowExecutionStatistic(namespace, name string, workflowTemplateID int64, createdAt time.Time, workflowOutcomeIsSuccess bool) (err error) {
|
||||||
|
tx, err := c.DB.Begin()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer tx.Rollback()
|
||||||
|
if workflowOutcomeIsSuccess {
|
||||||
|
_, err := sb.Insert("workflow_executions").
|
||||||
|
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 {
|
||||||
|
_, err := sb.Insert("workflow_executions").
|
||||||
|
SetMap(sq.Eq{
|
||||||
|
"workflow_template_id": workflowTemplateID,
|
||||||
|
"name": name,
|
||||||
|
"namespace": namespace,
|
||||||
|
"created_at": createdAt.UTC(),
|
||||||
|
"failed_at": time.Now().UTC(),
|
||||||
|
}).RunWith(tx).Exec()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = tx.Commit()
|
||||||
|
if err != nil {
|
||||||
|
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{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Reference in New Issue
Block a user