Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add bulk cancel functionality for analyses #769

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 38 additions & 7 deletions api/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const (
TaskBucketContentRoot = TaskBucketRoot + "/*" + Wildcard
TaskSubmitRoot = TaskRoot + "/submit"
TaskCancelRoot = TaskRoot + "/cancel"
TaskCancelListRoot = TasksRoot + "/cancel/list"
)

const (
Expand Down Expand Up @@ -59,6 +60,7 @@ func (h TaskHandler) AddRoutes(e *gin.Engine) {
// Actions
routeGroup.PUT(TaskSubmitRoot, Transaction, h.Submit)
routeGroup.PUT(TaskCancelRoot, h.Cancel)
routeGroup.PUT(TaskCancelListRoot, h.CancelList)
// Bucket
routeGroup = e.Group("/")
routeGroup.Use(Required("tasks.bucket"))
Expand Down Expand Up @@ -468,13 +470,13 @@ func (h TaskHandler) Submit(ctx *gin.Context) {
h.Update(ctx)
}

// Cancel godoc
// @summary Cancel a task.
// @description Cancel a task.
// @tags tasks
// @success 202
// @router /tasks/{id}/cancel [put]
// @param id path int true "Task ID"
// // Cancel godoc
// // @summary Cancel a task.
// // @description Cancel a task.
// // @tags tasks
// // @success 202
// // @router /tasks/{id}/cancel [put]
// // @param id path int true "Task ID"
func (h TaskHandler) Cancel(ctx *gin.Context) {
id := h.pk(ctx)
rtx := RichContext(ctx)
Expand All @@ -487,6 +489,35 @@ func (h TaskHandler) Cancel(ctx *gin.Context) {
h.Status(ctx, http.StatusAccepted)
}

// CancelList godoc
// @summary Cancel multiple tasks.
// @description Cancel multiple tasks by IDs.
// @tags tasks
// @success 202
// @router /tasks/cancel/list [put]
// @param tasks body []uint true "List of Task IDs"
func (h TaskHandler) CancelList(ctx *gin.Context) {
ids := []uint{}

if err := h.Bind(ctx, &ids); err != nil {
_ = ctx.Error(err)
return
}

rtx := RichContext(ctx)

for _, id := range ids {
err := rtx.TaskManager.Cancel(h.DB(ctx), id)
if err != nil {
_ = ctx.Error(err)
return
}
}

h.Status(ctx, http.StatusAccepted)
}


// BucketGet godoc
// @summary Get bucket content by ID and path.
// @description Get bucket content by ID and path.
Expand Down
6 changes: 6 additions & 0 deletions binding/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ func (h *Task) List() (list []api.Task, err error) {
return
}

// CancelMultipleTasks - Cancel multiple tasks by their IDs.
func (h *Task) CancelMultipleTasks(ids []uint) (err error) {
err = h.client.Put(api.TaskCancelListRoot, ids)
return
}

// Update a Task.
func (h *Task) Update(r *api.Task) (err error) {
path := Path(api.TaskRoot).Inject(Params{api.ID: r.ID})
Expand Down
Loading