-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
orm.go
544 lines (472 loc) · 20 KB
/
orm.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
package pipeline
import (
"context"
"database/sql"
"time"
"github.com/pkg/errors"
uuid "github.com/satori/go.uuid"
"github.com/smartcontractkit/chainlink/core/logger"
"github.com/smartcontractkit/chainlink/core/services/pg"
"github.com/smartcontractkit/chainlink/core/store/models"
"github.com/smartcontractkit/sqlx"
)
// KeepersObservationSource is the same for all keeper jobs and it is not persisted in DB
const KeepersObservationSource = `
encode_check_upkeep_tx [type=ethabiencode
abi="checkUpkeep(uint256 id, address from)"
data="{\"id\":$(jobSpec.upkeepID),\"from\":$(jobSpec.effectiveKeeperAddress)}"]
check_upkeep_tx [type=ethcall
failEarly=true
extractRevertReason=true
evmChainID="$(jobSpec.evmChainID)"
contract="$(jobSpec.contractAddress)"
gasUnlimited=true
gasPrice="$(jobSpec.gasPrice)"
gasTipCap="$(jobSpec.gasTipCap)"
gasFeeCap="$(jobSpec.gasFeeCap)"
data="$(encode_check_upkeep_tx)"]
decode_check_upkeep_tx [type=ethabidecode
abi="bytes memory performData, uint256 maxLinkPayment, uint256 gasLimit, uint256 adjustedGasWei, uint256 linkEth"]
calculate_perform_data_len [type=length
input="$(decode_check_upkeep_tx.performData)"]
perform_data_lessthan_limit [type=lessthan
left="$(calculate_perform_data_len)"
right="$(jobSpec.maxPerformDataSize)"]
check_perform_data_limit [type=conditional
failEarly=true
data="$(perform_data_lessthan_limit)"]
encode_perform_upkeep_tx [type=ethabiencode
abi="performUpkeep(uint256 id, bytes calldata performData)"
data="{\"id\": $(jobSpec.upkeepID),\"performData\":$(decode_check_upkeep_tx.performData)}"]
simulate_perform_upkeep_tx [type=ethcall
extractRevertReason=true
evmChainID="$(jobSpec.evmChainID)"
contract="$(jobSpec.contractAddress)"
from="$(jobSpec.effectiveKeeperAddress)"
gasUnlimited=true
data="$(encode_perform_upkeep_tx)"]
decode_check_perform_tx [type=ethabidecode
abi="bool success"]
check_success [type=conditional
failEarly=true
data="$(decode_check_perform_tx.success)"]
perform_upkeep_tx [type=ethtx
minConfirmations=0
to="$(jobSpec.contractAddress)"
from="[$(jobSpec.fromAddress)]"
evmChainID="$(jobSpec.evmChainID)"
data="$(encode_perform_upkeep_tx)"
gasLimit="$(jobSpec.performUpkeepGasLimit)"
txMeta="{\"jobID\":$(jobSpec.jobID),\"upkeepID\":$(jobSpec.prettyID)}"]
encode_check_upkeep_tx -> check_upkeep_tx -> decode_check_upkeep_tx -> calculate_perform_data_len -> perform_data_lessthan_limit -> check_perform_data_limit -> encode_perform_upkeep_tx -> simulate_perform_upkeep_tx -> decode_check_perform_tx -> check_success -> perform_upkeep_tx
`
//go:generate mockery --quiet --name ORM --output ./mocks/ --case=underscore
type ORM interface {
CreateSpec(pipeline Pipeline, maxTaskTimeout models.Interval, qopts ...pg.QOpt) (int32, error)
CreateRun(run *Run, qopts ...pg.QOpt) (err error)
InsertRun(run *Run, qopts ...pg.QOpt) error
DeleteRun(id int64) error
StoreRun(run *Run, qopts ...pg.QOpt) (restart bool, err error)
UpdateTaskRunResult(taskID uuid.UUID, result Result) (run Run, start bool, err error)
InsertFinishedRun(run *Run, saveSuccessfulTaskRuns bool, qopts ...pg.QOpt) (err error)
// InsertFinishedRuns inserts all the given runs into the database.
// If saveSuccessfulTaskRuns is false, only errored runs are saved.
InsertFinishedRuns(run []*Run, saveSuccessfulTaskRuns bool, qopts ...pg.QOpt) (err error)
DeleteRunsOlderThan(context.Context, time.Duration) error
FindRun(id int64) (Run, error)
GetAllRuns() ([]Run, error)
GetUnfinishedRuns(context.Context, time.Time, func(run Run) error) error
GetQ() pg.Q
}
type orm struct {
q pg.Q
lggr logger.Logger
}
var _ ORM = (*orm)(nil)
func NewORM(db *sqlx.DB, lggr logger.Logger, cfg pg.QConfig) *orm {
return &orm{pg.NewQ(db, lggr, cfg), lggr}
}
func (o *orm) CreateSpec(pipeline Pipeline, maxTaskDuration models.Interval, qopts ...pg.QOpt) (id int32, err error) {
q := o.q.WithOpts(qopts...)
sql := `INSERT INTO pipeline_specs (dot_dag_source, max_task_duration, created_at)
VALUES ($1, $2, NOW())
RETURNING id;`
err = q.Get(&id, sql, pipeline.Source, maxTaskDuration)
return id, errors.WithStack(err)
}
func (o *orm) CreateRun(run *Run, qopts ...pg.QOpt) (err error) {
if run.CreatedAt.IsZero() {
return errors.New("run.CreatedAt must be set")
}
q := o.q.WithOpts(qopts...)
err = q.Transaction(func(tx pg.Queryer) error {
if e := o.InsertRun(run, pg.WithQueryer(tx)); e != nil {
return errors.Wrap(e, "error inserting pipeline_run")
}
// Now create pipeline_task_runs if any
if len(run.PipelineTaskRuns) == 0 {
return nil
}
// update the ID key everywhere
for i := range run.PipelineTaskRuns {
run.PipelineTaskRuns[i].PipelineRunID = run.ID
}
sql := `
INSERT INTO pipeline_task_runs (pipeline_run_id, id, type, index, output, error, dot_id, created_at)
VALUES (:pipeline_run_id, :id, :type, :index, :output, :error, :dot_id, :created_at);`
_, err = tx.NamedExec(sql, run.PipelineTaskRuns)
return err
})
return errors.Wrap(err, "CreateRun failed")
}
// InsertRun inserts a run into the database
func (o *orm) InsertRun(run *Run, qopts ...pg.QOpt) error {
q := o.q.WithOpts(qopts...)
sql := `INSERT INTO pipeline_runs (pipeline_spec_id, meta, all_errors, fatal_errors, inputs, outputs, created_at, finished_at, state)
VALUES (:pipeline_spec_id, :meta, :all_errors, :fatal_errors, :inputs, :outputs, :created_at, :finished_at, :state)
RETURNING *;`
return q.GetNamed(sql, run, run)
}
// StoreRun will persist a partially executed run before suspending, or finish a run.
// If `restart` is true, then new task run data is available and the run should be resumed immediately.
func (o *orm) StoreRun(run *Run, qopts ...pg.QOpt) (restart bool, err error) {
q := o.q.WithOpts(qopts...)
err = q.Transaction(func(tx pg.Queryer) error {
finished := run.FinishedAt.Valid
if !finished {
// Lock the current run. This prevents races with /v2/resume
sql := `SELECT id FROM pipeline_runs WHERE id = $1 FOR UPDATE;`
if _, err = tx.Exec(sql, run.ID); err != nil {
return errors.Wrap(err, "StoreRun")
}
taskRuns := []TaskRun{}
// Reload task runs, we want to check for any changes while the run was ongoing
if err = sqlx.Select(tx, &taskRuns, `SELECT * FROM pipeline_task_runs WHERE pipeline_run_id = $1`, run.ID); err != nil {
return errors.Wrap(err, "StoreRun")
}
// Construct a temporary run so we can use r.ByDotID
tempRun := Run{PipelineTaskRuns: taskRuns}
// Diff with current state, if updated, swap run.PipelineTaskRuns and early return with restart = true
for i, tr := range run.PipelineTaskRuns {
if !tr.IsPending() {
continue
}
// Look for new data
if taskRun := tempRun.ByDotID(tr.DotID); taskRun != nil && !taskRun.IsPending() {
// Swap in the latest state
run.PipelineTaskRuns[i] = *taskRun
restart = true
}
}
if restart {
return nil
}
// Suspend the run
run.State = RunStatusSuspended
if _, err = sqlx.NamedExec(tx, `UPDATE pipeline_runs SET state = :state WHERE id = :id`, run); err != nil {
return errors.Wrap(err, "StoreRun")
}
} else {
// Simply finish the run, no need to do any sort of locking
if run.Outputs.Val == nil || len(run.FatalErrors)+len(run.AllErrors) == 0 {
return errors.Errorf("run must have both Outputs and Errors, got Outputs: %#v, FatalErrors: %#v, AllErrors: %#v", run.Outputs.Val, run.FatalErrors, run.AllErrors)
}
sql := `UPDATE pipeline_runs SET state = :state, finished_at = :finished_at, all_errors= :all_errors, fatal_errors= :fatal_errors, outputs = :outputs WHERE id = :id`
if _, err = sqlx.NamedExec(tx, sql, run); err != nil {
return errors.Wrap(err, "StoreRun")
}
}
sql := `
INSERT INTO pipeline_task_runs (pipeline_run_id, id, type, index, output, error, dot_id, created_at, finished_at)
VALUES (:pipeline_run_id, :id, :type, :index, :output, :error, :dot_id, :created_at, :finished_at)
ON CONFLICT (pipeline_run_id, dot_id) DO UPDATE SET
output = EXCLUDED.output, error = EXCLUDED.error, finished_at = EXCLUDED.finished_at
RETURNING *;
`
// NOTE: can't use Select() to auto scan because we're using NamedQuery,
// sqlx.Named + Select is possible but it's about the same amount of code
var rows *sqlx.Rows
rows, err = sqlx.NamedQuery(tx, sql, run.PipelineTaskRuns)
if err != nil {
return errors.Wrap(err, "StoreRun")
}
taskRuns := []TaskRun{}
if err = sqlx.StructScan(rows, &taskRuns); err != nil {
return errors.Wrap(err, "StoreRun")
}
// replace with new task run data
run.PipelineTaskRuns = taskRuns
return nil
})
return
}
// DeleteRun cleans up a run that failed and is marked failEarly (should leave no trace of the run)
func (o *orm) DeleteRun(id int64) error {
// NOTE: this will cascade and wipe pipeline_task_runs too
_, err := o.q.Exec(`DELETE FROM pipeline_runs WHERE id = $1`, id)
return err
}
func (o *orm) UpdateTaskRunResult(taskID uuid.UUID, result Result) (run Run, start bool, err error) {
if result.OutputDB().Valid && result.ErrorDB().Valid {
panic("run result must specify either output or error, not both")
}
err = o.q.Transaction(func(tx pg.Queryer) error {
sql := `
SELECT pipeline_runs.*, pipeline_specs.dot_dag_source "pipeline_spec.dot_dag_source"
FROM pipeline_runs
JOIN pipeline_task_runs ON (pipeline_task_runs.pipeline_run_id = pipeline_runs.id)
JOIN pipeline_specs ON (pipeline_specs.id = pipeline_runs.pipeline_spec_id)
WHERE pipeline_task_runs.id = $1 AND pipeline_runs.state in ('running', 'suspended')
FOR UPDATE`
if err = tx.Get(&run, sql, taskID); err != nil {
return err
}
// Update the task with result
sql = `UPDATE pipeline_task_runs SET output = $2, error = $3, finished_at = $4 WHERE id = $1`
if _, err = tx.Exec(sql, taskID, result.OutputDB(), result.ErrorDB(), time.Now()); err != nil {
return errors.Wrap(err, "UpdateTaskRunResult")
}
if run.State == RunStatusSuspended {
start = true
run.State = RunStatusRunning
sql = `UPDATE pipeline_runs SET state = $2 WHERE id = $1`
if _, err = tx.Exec(sql, run.ID, run.State); err != nil {
return errors.Wrap(err, "UpdateTaskRunResult")
}
}
return loadAssociations(tx, []*Run{&run})
})
return run, start, err
}
// InsertFinishedRuns inserts all the given runs into the database.
func (o *orm) InsertFinishedRuns(runs []*Run, saveSuccessfulTaskRuns bool, qopts ...pg.QOpt) error {
q := o.q.WithOpts(qopts...)
err := q.Transaction(func(tx pg.Queryer) error {
pipelineRunsQuery := `
INSERT INTO pipeline_runs
(pipeline_spec_id, meta, all_errors, fatal_errors, inputs, outputs, created_at, finished_at, state)
VALUES
(:pipeline_spec_id, :meta, :all_errors, :fatal_errors, :inputs, :outputs, :created_at, :finished_at, :state)
RETURNING id
`
rows, errQ := tx.NamedQuery(pipelineRunsQuery, runs)
if errQ != nil {
return errors.Wrap(errQ, "inserting finished pipeline runs")
}
var runIDs []int64
for rows.Next() {
var runID int64
if errS := rows.Scan(&runID); errS != nil {
return errors.Wrap(errS, "scanning pipeline runs id row")
}
runIDs = append(runIDs, runID)
}
for i, run := range runs {
for j := range run.PipelineTaskRuns {
run.PipelineTaskRuns[j].PipelineRunID = runIDs[i]
}
}
pipelineTaskRunsQuery := `
INSERT INTO pipeline_task_runs (pipeline_run_id, id, type, index, output, error, dot_id, created_at, finished_at)
VALUES (:pipeline_run_id, :id, :type, :index, :output, :error, :dot_id, :created_at, :finished_at);
`
var pipelineTaskRuns []TaskRun
for _, run := range runs {
if !saveSuccessfulTaskRuns && !run.HasErrors() {
continue
}
pipelineTaskRuns = append(pipelineTaskRuns, run.PipelineTaskRuns...)
}
_, errE := tx.NamedExec(pipelineTaskRunsQuery, pipelineTaskRuns)
return errors.Wrap(errE, "insert pipeline task runs")
})
return errors.Wrap(err, "InsertFinishedRuns failed")
}
func (o *orm) checkFinishedRun(run *Run, saveSuccessfulTaskRuns bool) error {
if run.CreatedAt.IsZero() {
return errors.New("run.CreatedAt must be set")
}
if run.FinishedAt.IsZero() {
return errors.New("run.FinishedAt must be set")
}
if run.Outputs.Val == nil || len(run.FatalErrors)+len(run.AllErrors) == 0 {
return errors.Errorf("run must have both Outputs and Errors, got Outputs: %#v, FatalErrors: %#v, AllErrors: %#v", run.Outputs.Val, run.FatalErrors, run.AllErrors)
}
if len(run.PipelineTaskRuns) == 0 && (saveSuccessfulTaskRuns || run.HasErrors()) {
return errors.New("must provide task run results")
}
return nil
}
// InsertFinishedRun inserts the given run into the database.
// If saveSuccessfulTaskRuns = false, we only save errored runs.
// That way if the job is run frequently (such as OCR) we avoid saving a large number of successful task runs
// which do not provide much value.
func (o *orm) InsertFinishedRun(run *Run, saveSuccessfulTaskRuns bool, qopts ...pg.QOpt) (err error) {
if err = o.checkFinishedRun(run, saveSuccessfulTaskRuns); err != nil {
return err
}
q := o.q.WithOpts(qopts...)
err = q.Transaction(func(tx pg.Queryer) error {
sql := `INSERT INTO pipeline_runs (pipeline_spec_id, meta, all_errors, fatal_errors, inputs, outputs, created_at, finished_at, state)
VALUES (:pipeline_spec_id, :meta, :all_errors, :fatal_errors, :inputs, :outputs, :created_at, :finished_at, :state)
RETURNING id;`
query, args, e := tx.BindNamed(sql, run)
if e != nil {
return errors.Wrap(e, "failed to bind")
}
if err = tx.QueryRowx(query, args...).Scan(&run.ID); err != nil {
return errors.Wrap(err, "error inserting finished pipeline_run")
}
// update the ID key everywhere
for i := range run.PipelineTaskRuns {
run.PipelineTaskRuns[i].PipelineRunID = run.ID
}
if !saveSuccessfulTaskRuns && !run.HasErrors() {
return nil
}
sql = `
INSERT INTO pipeline_task_runs (pipeline_run_id, id, type, index, output, error, dot_id, created_at, finished_at)
VALUES (:pipeline_run_id, :id, :type, :index, :output, :error, :dot_id, :created_at, :finished_at);`
_, err = tx.NamedExec(sql, run.PipelineTaskRuns)
return errors.Wrap(err, "failed to insert pipeline_task_runs")
})
return errors.Wrap(err, "InsertFinishedRun failed")
}
// DeleteRunsOlderThan deletes all pipeline_runs that have been finished for a certain threshold to free DB space
// Caller is expected to set timeout on calling context.
func (o *orm) DeleteRunsOlderThan(ctx context.Context, threshold time.Duration) error {
start := time.Now()
q := o.q.WithOpts(pg.WithParentCtxInheritTimeout(ctx))
queryThreshold := start.Add(-threshold)
err := pg.Batch(func(_, limit uint) (count uint, err error) {
result, cancel, err := q.ExecQIter(`
WITH batched_pipeline_runs AS (
SELECT * FROM pipeline_runs
WHERE finished_at < ($1)
ORDER BY finished_at ASC
LIMIT $2
)
DELETE FROM pipeline_runs
USING batched_pipeline_runs
WHERE pipeline_runs.id = batched_pipeline_runs.id`,
queryThreshold,
limit,
)
defer cancel()
if err != nil {
return count, errors.Wrap(err, "DeleteRunsOlderThan failed to delete old pipeline_runs")
}
rowsAffected, err := result.RowsAffected()
if err != nil {
return count, errors.Wrap(err, "DeleteRunsOlderThan failed to get rows affected")
}
return uint(rowsAffected), err
})
if err != nil {
return errors.Wrap(err, "DeleteRunsOlderThan failed")
}
deleteTS := time.Now()
o.lggr.Debugw("pipeline_runs reaper DELETE query completed", "duration", deleteTS.Sub(start))
defer func(start time.Time) {
o.lggr.Debugw("pipeline_runs reaper VACUUM ANALYZE query completed", "duration", time.Since(start))
}(deleteTS)
err = q.ExecQ("VACUUM ANALYZE pipeline_runs")
if err != nil {
o.lggr.Warnw("DeleteRunsOlderThan successfully deleted old pipeline_runs rows, but failed to run VACUUM ANALYZE", "err", err)
return nil
}
return nil
}
func (o *orm) FindRun(id int64) (r Run, err error) {
var runs []*Run
err = o.q.Transaction(func(tx pg.Queryer) error {
if err = tx.Select(&runs, `SELECT * from pipeline_runs WHERE id = $1 LIMIT 1`, id); err != nil {
return errors.Wrap(err, "failed to load runs")
}
return loadAssociations(tx, runs)
})
if len(runs) == 0 {
return r, sql.ErrNoRows
}
return *runs[0], err
}
func (o *orm) GetAllRuns() (runs []Run, err error) {
var runsPtrs []*Run
err = o.q.Transaction(func(tx pg.Queryer) error {
err = tx.Select(&runsPtrs, `SELECT * from pipeline_runs ORDER BY created_at ASC, id ASC`)
if err != nil {
return errors.Wrap(err, "failed to load runs")
}
return loadAssociations(tx, runsPtrs)
})
runs = make([]Run, len(runsPtrs))
for i, runPtr := range runsPtrs {
runs[i] = *runPtr
}
return runs, err
}
func (o *orm) GetUnfinishedRuns(ctx context.Context, now time.Time, fn func(run Run) error) error {
q := o.q.WithOpts(pg.WithParentCtx(ctx))
return pg.Batch(func(offset, limit uint) (count uint, err error) {
var runs []*Run
err = q.Transaction(func(tx pg.Queryer) error {
err = tx.Select(&runs, `SELECT * from pipeline_runs WHERE state = $1 AND created_at < $2 ORDER BY created_at ASC, id ASC OFFSET $3 LIMIT $4`, RunStatusRunning, now, offset, limit)
if err != nil {
return errors.Wrap(err, "failed to load runs")
}
err = loadAssociations(tx, runs)
if err != nil {
return err
}
for _, run := range runs {
if err = fn(*run); err != nil {
return err
}
}
return nil
})
return uint(len(runs)), err
})
}
// loads PipelineSpec and PipelineTaskRuns for Runs in exactly 2 queries
func loadAssociations(q pg.Queryer, runs []*Run) error {
if len(runs) == 0 {
return nil
}
var specs []Spec
pipelineSpecIDM := make(map[int32]Spec)
var pipelineSpecIDs []int32 // keyed by pipelineSpecID
pipelineRunIDs := make([]int64, len(runs))
for i, run := range runs {
pipelineRunIDs[i] = run.ID
if _, exists := pipelineSpecIDM[run.PipelineSpecID]; !exists {
pipelineSpecIDs = append(pipelineSpecIDs, run.PipelineSpecID)
pipelineSpecIDM[run.PipelineSpecID] = Spec{}
}
}
if err := q.Select(&specs, `SELECT ps.id, ps.dot_dag_source, ps.created_at, ps.max_task_duration, coalesce(jobs.id, 0) "job_id", coalesce(jobs.name, '') "job_name", coalesce(jobs.type, '') "job_type" FROM pipeline_specs ps LEFT OUTER JOIN jobs ON jobs.pipeline_spec_id=ps.id WHERE ps.id = ANY($1)`, pipelineSpecIDs); err != nil {
return errors.Wrap(err, "failed to postload pipeline_specs for runs")
}
for _, spec := range specs {
if spec.JobType == "keeper" {
spec.DotDagSource = KeepersObservationSource
}
pipelineSpecIDM[spec.ID] = spec
}
var taskRuns []TaskRun
taskRunPRIDM := make(map[int64][]TaskRun, len(runs)) // keyed by pipelineRunID
if err := q.Select(&taskRuns, `SELECT * FROM pipeline_task_runs WHERE pipeline_run_id = ANY($1) ORDER BY created_at ASC, id ASC`, pipelineRunIDs); err != nil {
return errors.Wrap(err, "failed to postload pipeline_task_runs for runs")
}
for _, taskRun := range taskRuns {
taskRunPRIDM[taskRun.PipelineRunID] = append(taskRunPRIDM[taskRun.PipelineRunID], taskRun)
}
for i, run := range runs {
runs[i].PipelineSpec = pipelineSpecIDM[run.PipelineSpecID]
runs[i].PipelineTaskRuns = taskRunPRIDM[run.ID]
}
return nil
}
func (o *orm) GetQ() pg.Q {
return o.q
}