@@ -25,16 +25,15 @@ const (
25
25
TasksReportRoot = TasksRoot + "/report"
26
26
TasksReportQueueRoot = TasksReportRoot + "/queue"
27
27
TasksReportDashboardRoot = TasksReportRoot + "/dashboard"
28
+ TasksCancelRoot = TasksRoot + "/cancel"
28
29
TaskRoot = TasksRoot + "/:" + ID
29
30
TaskReportRoot = TaskRoot + "/report"
30
31
TaskAttachedRoot = TaskRoot + "/attached"
31
32
TaskBucketRoot = TaskRoot + "/bucket"
32
33
TaskBucketContentRoot = TaskBucketRoot + "/*" + Wildcard
33
34
TaskSubmitRoot = TaskRoot + "/submit"
34
35
TaskCancelRoot = TaskRoot + "/cancel"
35
- TaskCancelListRoot = TasksRoot + "/cancel/list"
36
36
)
37
-
38
37
const (
39
38
Submit = "submit"
40
39
)
@@ -60,7 +59,7 @@ func (h TaskHandler) AddRoutes(e *gin.Engine) {
60
59
// Actions
61
60
routeGroup .PUT (TaskSubmitRoot , Transaction , h .Submit )
62
61
routeGroup .PUT (TaskCancelRoot , h .Cancel )
63
- routeGroup .PUT (TaskCancelListRoot , h .CancelList )
62
+ routeGroup .PUT (TasksCancelRoot , h .BulkCancel )
64
63
// Bucket
65
64
routeGroup = e .Group ("/" )
66
65
routeGroup .Use (Required ("tasks.bucket" ))
@@ -470,13 +469,13 @@ func (h TaskHandler) Submit(ctx *gin.Context) {
470
469
h .Update (ctx )
471
470
}
472
471
473
- // // Cancel godoc
474
- // // @summary Cancel a task.
475
- // // @description Cancel a task.
476
- // // @tags tasks
477
- // // @success 202
478
- // // @router /tasks/{id}/cancel [put]
479
- // // @param id path int true "Task ID"
472
+ // Cancel godoc
473
+ // @summary Cancel a task.
474
+ // @description Cancel a task.
475
+ // @tags tasks
476
+ // @success 202
477
+ // @router /tasks/{id}/cancel [put]
478
+ // @param id path int true "Task ID"
480
479
func (h TaskHandler ) Cancel (ctx * gin.Context ) {
481
480
id := h .pk (ctx )
482
481
rtx := RichContext (ctx )
@@ -489,35 +488,60 @@ func (h TaskHandler) Cancel(ctx *gin.Context) {
489
488
h .Status (ctx , http .StatusAccepted )
490
489
}
491
490
492
- // CancelList godoc
493
- // @summary Cancel multiple tasks.
494
- // @description Cancel multiple tasks by IDs.
491
+ // BulkCancel godoc
492
+ // @summary Cancel tasks matched by the filter.
493
+ // @description Cancel tasks matched by the filter.
494
+ // @description Caution: an empty filter matches all tasks.
495
+ // @description Filters:
496
+ // @description - id
497
+ // @description - name
498
+ // @description - locator
499
+ // @description - kind
500
+ // @description - addon
501
+ // @description - state
502
+ // @description - application.id
495
503
// @tags tasks
496
504
// @success 202
497
505
// @router /tasks/cancel/list [put]
498
506
// @param tasks body []uint true "List of Task IDs"
499
- func (h TaskHandler ) CancelList (ctx * gin.Context ) {
500
- ids := []uint {}
501
-
502
- if err := h .Bind (ctx , & ids ); err != nil {
503
- _ = ctx .Error (err )
504
- return
505
- }
506
-
507
- rtx := RichContext (ctx )
508
-
509
- for _ , id := range ids {
510
- err := rtx .TaskManager .Cancel (h .DB (ctx ), id )
511
- if err != nil {
512
- _ = ctx .Error (err )
513
- return
514
- }
515
- }
507
+ func (h TaskHandler ) BulkCancel (ctx * gin.Context ) {
508
+ filter , err := qf .New (ctx ,
509
+ []qf.Assert {
510
+ {Field : "id" , Kind : qf .LITERAL },
511
+ {Field : "name" , Kind : qf .STRING },
512
+ {Field : "locator" , Kind : qf .STRING },
513
+ {Field : "kind" , Kind : qf .STRING },
514
+ {Field : "addon" , Kind : qf .STRING },
515
+ {Field : "state" , Kind : qf .STRING },
516
+ {Field : "application.id" , Kind : qf .STRING },
517
+ })
518
+ if err != nil {
519
+ _ = ctx .Error (err )
520
+ return
521
+ }
522
+ filter = filter .Renamed ("application.id" , "applicationId" )
523
+ db := h .DB (ctx )
524
+ db = db .Model (& model.Task {})
525
+ db = filter .Where (db )
526
+ matched := []* model.Task {}
527
+ err = db .Find (& matched ).Error
528
+ if err != nil {
529
+ _ = ctx .Error (err )
530
+ return
531
+ }
532
+ db = h .DB (ctx )
533
+ rtx := RichContext (ctx )
534
+ for _ , m := range matched {
535
+ err := rtx .TaskManager .Cancel (db , m .ID )
536
+ if err != nil {
537
+ _ = ctx .Error (err )
538
+ return
539
+ }
540
+ }
516
541
517
- h .Status (ctx , http .StatusAccepted )
542
+ h .Status (ctx , http .StatusAccepted )
518
543
}
519
544
520
-
521
545
// BucketGet godoc
522
546
// @summary Get bucket content by ID and path.
523
547
// @description Get bucket content by ID and path.
0 commit comments