/
workflow_run.go
610 lines (547 loc) · 22.4 KB
/
workflow_run.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
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
package sdk
import (
"database/sql/driver"
json "encoding/json"
"fmt"
"sort"
"strings"
"time"
"github.com/blang/semver"
"github.com/sguiheux/go-coverage"
)
var (
WorkflowRunHeader = "X-Workflow-Run"
WorkflowHeader = "X-Workflow"
ProjectKeyHeader = "X-Project-Key"
)
type WorkflowRunHeaders map[string]string
func (h *WorkflowRunHeaders) Set(k, v string) {
if h == nil {
h = new(WorkflowRunHeaders)
}
(*h)[k] = v
}
func (h *WorkflowRunHeaders) Get(k string) (string, bool) {
if h == nil {
return "", false
}
v, has := (*h)[k]
return v, has
}
func (h WorkflowRunHeaders) Value() (driver.Value, error) {
j, err := json.Marshal(h)
return j, WrapError(err, "cannot marshal WorkflowRunHeaders")
}
func (h *WorkflowRunHeaders) Scan(src interface{}) error {
if src == nil {
return nil
}
source, ok := src.([]byte)
if !ok {
return WithStack(fmt.Errorf("type assertion .([]byte) failed (%T)", src))
}
return WrapError(JSONUnmarshal(source, h), "cannot unmarshal WorkflowRunHeaders")
}
// WorkflowRun is an execution instance of a run
type WorkflowRun struct {
ID int64 `json:"id" db:"id"`
Number int64 `json:"num" db:"num" cli:"num,key"`
Version *string `json:"version,omitempty" db:"version" cli:"version"`
ProjectID int64 `json:"project_id,omitempty" db:"project_id"`
WorkflowID int64 `json:"workflow_id" db:"workflow_id"`
Status string `json:"status" db:"status" cli:"status"`
Workflow Workflow `json:"workflow" db:"workflow"`
Start time.Time `json:"start" db:"start" cli:"start"`
LastModified time.Time `json:"last_modified" db:"last_modified"`
WorkflowNodeRuns map[int64][]WorkflowNodeRun `json:"nodes,omitempty" db:"-"`
Infos WorkflowRunInfos `json:"infos,omitempty" db:"infos"`
Tags []WorkflowRunTag `json:"tags,omitempty" db:"-" cli:"tags"`
LastSubNumber int64 `json:"last_subnumber" db:"last_sub_num"`
LastExecution time.Time `json:"last_execution" db:"last_execution" cli:"last_execution"`
ToDelete bool `json:"to_delete" db:"to_delete" cli:"-"`
JoinTriggersRun WorkflowNodeTriggerRuns `json:"join_triggers_run,omitempty" db:"join_triggers_run"`
Header WorkflowRunHeaders `json:"header,omitempty" db:"header"`
URLs URL `json:"urls" yaml:"-" db:"-" cli:"-"`
ReadOnly bool `json:"read_only" yaml:"-" db:"read_only" cli:"-"`
ToCraft bool `json:"-" yaml:"-" db:"to_craft" cli:"-"`
ToCraftOpts *WorkflowRunPostHandlerOption `json:"-" yaml:"-" db:"to_craft_opts" cli:"-"`
}
type WorkflowRunSummary struct {
ID int64 `json:"id" db:"id" cli:"-"`
Version *string `json:"version,omitempty" db:"version" cli:"version"`
Number int64 `json:"num" db:"num" cli:"num,key"`
Status string `json:"status" db:"status" cli:"status"`
Start time.Time `json:"start" db:"start" cli:"start"`
LastModified time.Time `json:"last_modified" db:"last_modified" cli:"-"`
LastSubNumber int64 `json:"last_subnumber" db:"last_sub_num" cli:"-"`
LastExecution time.Time `json:"last_execution" db:"last_execution" cli:"last_execution"`
ToCraftOpts *WorkflowRunPostHandlerOption `json:"-" yaml:"-" db:"to_craft_opts" cli:"-"`
Tags []WorkflowRunTag `json:"tags,omitempty" db:"-" cli:"tags"`
}
type WorkflowRunInfos []WorkflowRunInfo
func (a WorkflowRunInfos) Value() (driver.Value, error) {
j, err := json.Marshal(a)
return j, WrapError(err, "cannot marshal WorkflowRunInfos")
}
func (a *WorkflowRunInfos) Scan(src interface{}) error {
if src == nil {
return nil
}
source, ok := src.([]byte)
if !ok {
return WithStack(fmt.Errorf("type assertion .([]byte) failed (%T)", src))
}
return WrapError(JSONUnmarshal(source, a), "cannot unmarshal WorkflowRunInfos")
}
type WorkflowNodeTriggerRuns map[int64]WorkflowNodeTriggerRun
func (a WorkflowNodeTriggerRuns) Value() (driver.Value, error) {
j, err := json.Marshal(a)
return j, WrapError(err, "cannot marshal WorkflowNodeTriggerRuns")
}
func (a *WorkflowNodeTriggerRuns) Scan(src interface{}) error {
if src == nil {
return nil
}
source, ok := src.([]byte)
if !ok {
return WithStack(fmt.Errorf("type assertion .([]byte) failed (%T)", src))
}
return WrapError(JSONUnmarshal(source, a), "cannot unmarshal WorkflowNodeTriggerRuns")
}
type WorkflowRunSecrets []WorkflowRunSecret
func (s WorkflowRunSecrets) ToVariables() []Variable {
res := make([]Variable, len(s))
for i := range s {
res[i] = s[i].ToVariable()
}
return res
}
type WorkflowRunSecret struct {
ID string `json:"-" db:"id"`
WorkflowRunID int64 `json:"-" db:"workflow_run_id"`
Type string `json:"-" db:"type"`
Context string `json:"-" db:"context"`
Name string `json:"-" db:"name"`
Value []byte `json:"-" db:"cypher_value" gorpmapping:"encrypted,ID"`
}
func (s WorkflowRunSecret) ToVariable() Variable {
return Variable{
Name: s.Name,
Type: s.Type,
Value: string(s.Value),
}
}
// WorkflowNodeRunRelease represents the request struct use by release builtin action for workflow
type WorkflowNodeRunRelease struct {
TagName string `json:"tag_name"`
ReleaseTitle string `json:"release_title"`
ReleaseContent string `json:"release_content"`
Artifacts []string `json:"artifacts,omitempty"`
}
// WorkflowRunPostHandlerOption contains the body content for launch a workflow
type WorkflowRunPostHandlerOption struct {
Hook *WorkflowNodeRunHookEvent `json:"hook,omitempty"`
Manual *WorkflowNodeRunManual `json:"manual,omitempty"`
Number *int64 `json:"number,omitempty"`
FromNodeIDs []int64 `json:"from_nodes,omitempty"`
AuthConsumerID string `json:"auth_consumer,omitempty"`
}
// Value returns driver.Value from WorkflowRunPostHandlerOption.
func (a *WorkflowRunPostHandlerOption) Value() (driver.Value, error) {
j, err := json.Marshal(a)
return j, WrapError(err, "cannot marshal Author")
}
// Scan WorkflowRunPostHandlerOption.
func (a *WorkflowRunPostHandlerOption) Scan(src interface{}) error {
if src == nil {
return nil
}
source, ok := src.([]byte)
if !ok {
return WithStack(fmt.Errorf("type assertion .([]byte) failed (%T)", src))
}
return WrapError(JSONUnmarshal(source, a), "cannot unmarshal WorkflowRunPostHandlerOption")
}
// WorkflowRunNumber contains a workflow run number
type WorkflowRunNumber struct {
Num int64 `json:"num" cli:"run-number"`
}
// WorkflowRunVersion contains a workflow run version.
type WorkflowRunVersion struct {
Value string `json:"value"`
}
func (w WorkflowRunVersion) IsValid() error {
_, err := semver.ParseTolerant(w.Value)
if err != nil {
return NewError(ErrWrongRequest, fmt.Errorf("value %q is not semver compatible: %v", w.Value, err))
}
return nil
}
// Translate translates messages in WorkflowNodeRun
func (r *WorkflowRun) Translate() {
for ki, info := range r.Infos {
if _, ok := Messages[info.Message.ID]; ok {
m := NewMessage(Messages[info.Message.ID], info.Message.Args...)
r.Infos[ki].UserMessage = m.String()
}
}
}
func (r *WorkflowRun) PendingOutgoingHook() map[string]*WorkflowNodeRun {
nrs := make(map[string]*WorkflowNodeRun)
for i := range r.WorkflowNodeRuns {
runs := r.WorkflowNodeRuns[i]
if len(runs) > 0 && runs[0].OutgoingHook == nil {
continue
}
for j := range runs {
nr := &runs[j]
if nr.Status != StatusWaiting && nr.Status != StatusBuilding {
continue
}
nrs[nr.UUID] = nr
}
}
return nrs
}
// Tag push a new Tag in WorkflowRunTag and return if a tag was added or no
func (r *WorkflowRun) Tag(tag, value string) bool {
if value == "" {
return false
}
var found bool
for i := range r.Tags {
if r.Tags[i].Tag == tag {
found = true
tagValues := strings.Split(r.Tags[i].Value, ",")
var exist bool
for _, tagVal := range tagValues {
if tagVal == value {
exist = true
break
}
}
if !exist {
r.Tags[i].Value = strings.Join([]string{r.Tags[i].Value, value}, ",")
}
}
}
if !found {
r.Tags = append(r.Tags, WorkflowRunTag{Tag: tag, Value: value})
return true
}
return false
}
// TagExists returns true if tag already exists
func (r *WorkflowRun) TagExists(tag string) bool {
for i := range r.Tags {
if r.Tags[i].Tag == tag {
return true
}
}
return false
}
func (r *WorkflowRun) RootRun() *WorkflowNodeRun {
rootNodeRuns, has := r.WorkflowNodeRuns[r.Workflow.WorkflowData.Node.ID]
if !has || len(rootNodeRuns) < 1 {
return nil
}
rootRun := rootNodeRuns[0]
return &rootRun
}
func (r *WorkflowRun) HasParentWorkflow() bool {
rr := r.RootRun()
if rr == nil {
return false
}
if rr.HookEvent == nil {
return false
}
return rr.HookEvent.ParentWorkflow.Key != "" &&
rr.HookEvent.ParentWorkflow.Name != "" &&
rr.HookEvent.ParentWorkflow.Run != 0 &&
rr.HookEvent.ParentWorkflow.HookRunID != ""
}
func (r *WorkflowRun) GetOutgoingHookRun(uuid string) *WorkflowNodeRun {
for i := range r.WorkflowNodeRuns {
nodeRuns := r.WorkflowNodeRuns[i]
if len(nodeRuns) == 0 || nodeRuns[0].OutgoingHook == nil {
continue
}
for j := range nodeRuns {
nr := &nodeRuns[j]
if nr.UUID == uuid {
return nr
}
}
}
return nil
}
func (r *WorkflowRun) GetAllParameters() map[string][]string {
params := make(map[string][]string)
for i := range r.WorkflowNodeRuns {
nodeRuns := r.WorkflowNodeRuns[i]
for j := range nodeRuns {
nodeRun := &nodeRuns[j]
for _, stage := range nodeRun.Stages {
for _, job := range stage.RunJobs {
for _, param := range job.Parameters {
if param.Value != "" {
params[param.Name] = append(params[param.Name], param.Value)
}
}
}
}
}
}
return params
}
const (
RunInfoTypInfo = "Info"
RunInfoTypeWarning = "Warning"
RunInfoTypeError = "Error"
)
// WorkflowRunInfo is an info on workflow run
type WorkflowRunInfo struct {
APITime time.Time `json:"api_time,omitempty" db:"-"`
Message SpawnMsg `json:"message,omitempty" db:"-"`
// UserMessage contains msg translated for end user
UserMessage string `json:"user_message,omitempty" db:"-"`
SubNumber int64 `json:"sub_number,omitempty" db:"-"`
Type string `json:"type" db:"-"`
}
// WorkflowRunTag is a tag on workflow run
type WorkflowRunTag struct {
WorkflowRunID int64 `json:"-" db:"workflow_run_id"`
Tag string `json:"tag,omitempty" db:"tag" cli:"tag"`
Value string `json:"value,omitempty" db:"value" cli:"value"`
}
// WorkflowNodeRun is as execution instance of a node. This type is duplicated for database persistence in the engine/api/workflow package
type WorkflowNodeRun struct {
WorkflowRunID int64 `json:"workflow_run_id"`
WorkflowID int64 `json:"workflow_id"`
ApplicationID int64 `json:"application_id"`
ID int64 `json:"id"`
WorkflowNodeID int64 `json:"workflow_node_id"`
WorkflowNodeName string `json:"workflow_node_name"`
Number int64 `json:"num"`
SubNumber int64 `json:"subnumber"`
Status string `json:"status"`
Stages []Stage `json:"stages,omitempty"`
Start time.Time `json:"start"`
LastModified time.Time `json:"last_modified"`
Done time.Time `json:"done"`
HookEvent *WorkflowNodeRunHookEvent `json:"hook_event,omitempty"`
Manual *WorkflowNodeRunManual `json:"manual,omitempty"`
SourceNodeRuns []int64 `json:"source_node_runs,omitempty"`
Payload interface{} `json:"payload,omitempty"`
PipelineParameters []Parameter `json:"pipeline_parameters,omitempty"`
BuildParameters []Parameter `json:"build_parameters,omitempty"`
Contexts NodeRunContext `json:"contexts,omitempty"`
Coverage WorkflowNodeRunCoverage `json:"coverage,omitempty"`
Tests *TestsResults `json:"tests,omitempty"`
Commits []VCSCommit `json:"commits,omitempty"`
TriggersRun map[int64]WorkflowNodeTriggerRun `json:"triggers_run,omitempty"`
VCSRepository string `json:"vcs_repository"`
VCSTag string `json:"vcs_tag"`
VCSBranch string `json:"vcs_branch"`
VCSHash string `json:"vcs_hash"`
VCSServer string `json:"vcs_server"`
CanBeRun bool `json:"can_be_run"`
Header WorkflowRunHeaders `json:"header,omitempty"`
UUID string `json:"uuid,omitempty"`
OutgoingHook *NodeOutGoingHook `json:"outgoinghook,omitempty"`
HookExecutionTimeStamp int64 `json:"hook_execution_timestamp,omitempty"`
HookExecutionID string `json:"execution_id,omitempty"`
Callback *WorkflowNodeOutgoingHookRunCallback `json:"callback,omitempty"`
VCSReport string `json:"vcs_report,omitempty"`
}
func (nodeRun *WorkflowNodeRun) GetStageIndex(job *WorkflowNodeJobRun) int {
var stageIndex = -1
for i := range nodeRun.Stages {
s := &nodeRun.Stages[i]
for _, j := range s.Jobs {
if j.Action.ID == job.Job.Job.Action.ID {
stageIndex = i
}
}
}
return stageIndex
}
// WorkflowNodeOutgoingHookRunCallback is the callback coming from hooks uservice avec an outgoing hook execution
type WorkflowNodeOutgoingHookRunCallback struct {
NodeHookID int64 `json:"workflow_node_outgoing_hook_id"`
Start time.Time `json:"start"`
Done time.Time `json:"done"`
Status string `json:"status"`
Log string `json:"log"`
WorkflowRunNumber *int64 `json:"workflow_run_number"`
}
// WorkflowNodeRunVulnerability content of the workflow node run vulnerability report
type WorkflowNodeRunVulnerability struct {
Summary map[string]int64 `json:"summary"`
DefaultBranchSummary map[string]int64 `json:"default_branch_summary"`
PreviousRunSummary map[string]int64 `json:"previous_run_summary"`
}
// WorkflowNodeRunCoverage represents the code coverage report
type WorkflowNodeRunCoverage struct {
WorkflowID int64 `json:"workflow_id" db:"workflow_id"`
WorkflowNodeRunID int64 `json:"workflow_node_run_id" db:"workflow_node_run_id"`
WorkflowRunID int64 `json:"workflow_run_id" db:"workflow_run_id"`
ApplicationID int64 `json:"application_id" db:"application_id"`
Num int64 `json:"run_number" db:"run_number"`
Repository string `json:"repository" db:"repository"`
Branch string `json:"branch" db:"branch"`
Report coverage.Report `json:"report" db:"-"`
Trend WorkflowNodeRunCoverageTrends `json:"trend" db:"-"`
}
// WorkflowNodeRunCoverageTrends represents code coverage trend with current branch and default branch
type WorkflowNodeRunCoverageTrends struct {
CurrentBranch coverage.Report `json:"current_branch_report"`
DefaultBranch coverage.Report `json:"default_branch_report"`
}
// WorkflowNodeTriggerRun Represent the state of a trigger
type WorkflowNodeTriggerRun struct {
WorkflowDestNodeID int64 `json:"workflow_dest_node_id" db:"-"`
Status string `json:"status" db:"-"`
}
// Translate translates messages in WorkflowNodeRun
func (nr *WorkflowNodeRun) Translate() {
for ks := range nr.Stages {
for kj := range nr.Stages[ks].RunJobs {
nr.Stages[ks].RunJobs[kj].Translate()
}
}
}
// WorkflowNodeJobRun represents an job to be run
type WorkflowNodeJobRun struct {
ProjectID int64 `json:"project_id"`
ID int64 `json:"id"`
WorkflowNodeRunID int64 `json:"workflow_node_run_id,omitempty"`
Job ExecutedJob `json:"job"`
Parameters []Parameter `json:"parameters,omitempty"`
Status string `json:"status"`
Retry int `json:"retry"`
Queued time.Time `json:"queued,omitempty" cli:"queued"`
QueuedSeconds int64 `json:"queued_seconds,omitempty"`
Start time.Time `json:"start,omitempty"`
Done time.Time `json:"done,omitempty"`
Model string `json:"model,omitempty"`
ModelType string `json:"model_type,omitempty"`
Region *string `json:"region,omitempty"`
BookedBy BookedBy `json:"bookedby,omitempty"`
SpawnInfos []SpawnInfo `json:"spawninfos"`
ExecGroups Groups `json:"exec_groups"`
Header WorkflowRunHeaders `json:"header,omitempty"`
ContainsService bool `json:"contains_service,omitempty"`
HatcheryName string `json:"hatchery_name,omitempty"`
WorkerName string `json:"worker_name,omitempty"`
IntegrationPlugins []GRPCPlugin `json:"integration_plugin,omitempty"`
Contexts JobRunContext `json:"-"`
}
type BookedBy struct {
Name string `json:"name,omitempty"`
ID int64 `json:"id,omitempty"`
}
// WorkflowNodeJobRunSummary is a light representation of WorkflowNodeJobRun for CDS event
type WorkflowNodeJobRunSummary struct {
ID int64 `json:"id"`
WorkflowNodeRunID int64 `json:"workflow_node_run_id,omitempty"`
Status string `json:"status"`
Queued int64 `json:"queued,omitempty"`
Start int64 `json:"start,omitempty"`
Done int64 `json:"done,omitempty"`
Job ExecutedJobSummary `json:"job_summary,omitempty"`
SpawnInfos []SpawnInfo `json:"spawninfos"`
HatcheryName string `json:"hatchery_name,omitempty"`
WorkerName string `json:"worker_name,omitempty"`
WorkerModelName string `json:"worker_model_name,omitempty"`
}
// ToSummary transforms a WorkflowNodeJobRun into a WorkflowNodeJobRunSummary
func (wnjr WorkflowNodeJobRun) ToSummary() WorkflowNodeJobRunSummary {
sum := WorkflowNodeJobRunSummary{
Done: wnjr.Done.Unix(),
WorkflowNodeRunID: wnjr.WorkflowNodeRunID,
Status: wnjr.Status,
ID: wnjr.ID,
Queued: wnjr.Queued.Unix(),
Start: wnjr.Start.Unix(),
Job: wnjr.Job.ToSummary(),
SpawnInfos: wnjr.SpawnInfos,
}
return sum
}
// WorkflowNodeJobRunInfo represents info on a job
type WorkflowNodeJobRunInfo struct {
ID int64 `json:"id"`
WorkflowNodeJobRunID int64 `json:"workflow_node_job_run_id,omitempty"`
WorkflowNodeRunID int64 `json:"workflow_node_run_id,omitempty"`
SpawnInfos []SpawnInfo `json:"info"`
Created time.Time `json:"created"`
}
type WorkflowNodeJobRunBooked struct {
ProjectKey string `json:"project_key"`
WorkflowName string `json:"workflow_name"`
WorkflowID int64 `json:"workflow_id"`
RunID int64 `json:"run_id"`
NodeRunName string `json:"node_run_name"`
NodeRunID int64 `json:"node_run_id"`
JobName string `json:"job_name"`
}
// Translate translates messages in WorkflowNodeJobRun
func (wnjr *WorkflowNodeJobRun) Translate() {
for ki, info := range wnjr.SpawnInfos {
if _, ok := Messages[info.Message.ID]; ok {
m := NewMessage(Messages[info.Message.ID], info.Message.Args...)
wnjr.SpawnInfos[ki].UserMessage = m.String()
}
}
}
func (wnjr *WorkflowNodeJobRun) GetPuginBinary(pluginType string, os string, arch string) *GRPCPluginBinary {
for _, p := range wnjr.IntegrationPlugins {
if p.Type != pluginType {
continue
}
for _, b := range p.Binaries {
if b.OS == os && b.Arch == arch {
return &b
}
}
}
return nil
}
// WorkflowNodeRunHookEvent is an instanc of event received on a hook
type WorkflowNodeRunHookEvent struct {
Payload map[string]string `json:"payload" db:"-"`
WorkflowNodeHookUUID string `json:"uuid" db:"-"`
ParentWorkflow struct {
Key string `json:"key" db:"-"`
Name string `json:"name" db:"-"`
Run int64 `json:"run" db:"-"`
HookRunID string `hook_run_id:"uuid" db:"-"`
} `json:"parent_workflow" db:"-"`
}
// WorkflowNodeRunManual is an instanc of event received on a hook
type WorkflowNodeRunManual struct {
Payload interface{} `json:"payload" db:"-"`
PipelineParameters []Parameter `json:"pipeline_parameter" db:"-"`
OnlyFailedJobs bool `json:"only_failed_jobs" db:"-"`
Resync bool `json:"resync" db:"-"`
Username string `json:"username" db:"-"`
Fullname string `json:"fullname" db:"-"`
Email string `json:"email" db:"-"`
}
type WorkflowQueue []WorkflowNodeJobRun
func (q WorkflowQueue) Sort() {
//Count the number of WorkflowNodeJobRun per project_id
n := make(map[int64]int, len(q))
for _, j := range q {
nb := n[j.ProjectID]
nb++
n[j.ProjectID] = nb
}
sort.Slice(q, func(i, j int) bool {
p1 := n[q[i].ProjectID]
p2 := n[q[j].ProjectID]
return p1 < p2
})
}