MCPcopy Create free account
hub / github.com/bytebase/bytebase / ListTaskRuns

Method ListTaskRuns

backend/store/task_run.go:64–190  ·  view source on GitHub ↗

ListTaskRuns lists task runs.

(ctx context.Context, find *FindTaskRunMessage)

Source from the content-addressed store, hash-verified

62
63// ListTaskRuns lists task runs.
64func (s *Store) ListTaskRuns(ctx context.Context, find *FindTaskRunMessage) ([]*TaskRunMessage, error) {
65 if find.ProjectID == "" && (find.UID != nil || find.UIDs != nil || find.TaskUID != nil || find.Environment != nil || find.PlanUID != nil) {
66 return nil, errors.Errorf("project ID is required for scoped task run filters")
67 }
68
69 where := qb.Q()
70 if find.ProjectID != "" {
71 where.And("task_run.project = ?", find.ProjectID)
72 }
73 if find.Workspace != "" {
74 where.And("task_run.project IN (SELECT resource_id FROM project WHERE workspace = ?)", find.Workspace)
75 }
76 if v := find.UID; v != nil {
77 where.And("task_run.id = ?", *v)
78 }
79 if v := find.UIDs; v != nil {
80 where.And("task_run.id = ANY(?)", *v)
81 }
82 if v := find.TaskUID; v != nil {
83 where.And("task_run.task_id = ?", *v)
84 }
85 if v := find.Environment; v != nil {
86 where.And("task.environment = ?", *v)
87 }
88 if v := find.PlanUID; v != nil {
89 where.And("task.plan_id = ?", *v)
90 }
91 if v := find.Status; v != nil {
92 var statusStrings []string
93 for _, status := range *v {
94 statusStrings = append(statusStrings, status.String())
95 }
96 where.And("task_run.status = ANY(?)", statusStrings)
97 }
98
99 q := qb.Q().Space(`
100 SELECT
101 task_run.id,
102 task_run.creator,
103 task_run.created_at,
104 task_run.updated_at,
105 task_run.task_id,
106 task_run.status,
107 task_run.started_at,
108 task_run.run_at,
109 task_run.result,
110 task_run.payload,
111 task.plan_id,
112 task.environment,
113 task_run.project
114 FROM task_run
115 LEFT JOIN task ON task.project = task_run.project AND task.id = task_run.task_id
116 `)
117 if where.Len() > 0 {
118 q.Space("WHERE ?", where)
119 }
120
121 q.Space("ORDER BY task_run.id ASC")

Callers 1

GetTaskRunV1Method · 0.95

Calls 13

GetDBMethod · 0.95
QFunction · 0.92
ErrorfMethod · 0.80
AndMethod · 0.80
SpaceMethod · 0.80
LenMethod · 0.80
ToSQLMethod · 0.80
QueryContextMethod · 0.80
ScanMethod · 0.80
UnmarshalMethod · 0.80
StringMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected