[GH-ISSUE #197] [FEATURE REQUEST] Filter or intercept the task on queue and do operations like Stop/Pause/Resume tasks #1079

Closed
opened 2026-03-07 22:05:23 +03:00 by kerem · 3 comments
Owner

Originally created by @sujit-baniya on GitHub (Sep 17, 2020).
Original GitHub issue: https://github.com/hibiken/asynq/issues/197

Originally assigned to: @hibiken on GitHub.

In Shared or Dedicated queue, it's good to have filter feature for tasks on queue. This feature will allow to do operations like Stop/Pause/Resume/Stats for the subset of tasks on queue.

By filter or Intercept the task, I mean before/after the task is put on the queue and consumer has still not consumed the task, I could filter the list of tasks by payload and do operations like Delay such task, Stop them or pause or resume them.

Use-Case:
Users are sending tasks to a dynamically created queue. As an admin, I could filter and group the list of tasks by any field in the payload and view the stats of tasks on queue. This would help me control the tasks per user or payload

Originally created by @sujit-baniya on GitHub (Sep 17, 2020). Original GitHub issue: https://github.com/hibiken/asynq/issues/197 Originally assigned to: @hibiken on GitHub. In Shared or Dedicated queue, it's good to have filter feature for tasks on queue. This feature will allow to do operations like Stop/Pause/Resume/Stats for the subset of tasks on queue. By filter or Intercept the task, I mean before/after the task is put on the queue and consumer has still not consumed the task, I could filter the list of tasks by payload and do operations like Delay such task, Stop them or pause or resume them. Use-Case: Users are sending tasks to a dynamically created queue. As an admin, I could filter and group the list of tasks by any field in the payload and view the stats of tasks on queue. This would help me control the tasks per user or payload
kerem 2026-03-07 22:05:23 +03:00
Author
Owner

@sujit-baniya commented on GitHub (Sep 17, 2020):

https://github.com/hibiken/asynq/issues/194

<!-- gh-comment-id:693763192 --> @sujit-baniya commented on GitHub (Sep 17, 2020): https://github.com/hibiken/asynq/issues/194
Author
Owner

@hibiken commented on GitHub (Sep 17, 2020):

Maybe not exactly what you need, but you can implement your Handler to do a pre-check.

If you are using ServeMux, you can accomplish this by adding a middleware, which will be called for all tasks regardless of its type.

Example:

func precheckMiddleware(h asynq.Handler) asynq.Handler {
    return asynq.HandlerFunc(func(ctx context.Context, t *asynq.Task) error {
        // do precheck and return error if you need to skip this task.
        if (/* some precheck condition */) {
            return fmt.Errorf("some error message")
        }
        // otherwise, invoke handler as normal.
        return h.ProcessTask(ctx, t)
    })
} 

// ...

mux := asynq.NewServeMux()
mux.Use(precheckMiddleware)
<!-- gh-comment-id:694242333 --> @hibiken commented on GitHub (Sep 17, 2020): Maybe not exactly what you need, but you can implement your `Handler` to do a pre-check. If you are using `ServeMux`, you can accomplish this by adding a middleware, which will be called for all tasks regardless of its type. Example: ```go func precheckMiddleware(h asynq.Handler) asynq.Handler { return asynq.HandlerFunc(func(ctx context.Context, t *asynq.Task) error { // do precheck and return error if you need to skip this task. if (/* some precheck condition */) { return fmt.Errorf("some error message") } // otherwise, invoke handler as normal. return h.ProcessTask(ctx, t) }) } // ... mux := asynq.NewServeMux() mux.Use(precheckMiddleware) ```
Author
Owner

@hibiken commented on GitHub (Feb 1, 2021):

Closing this issue. Seems stale.

<!-- gh-comment-id:770610929 --> @hibiken commented on GitHub (Feb 1, 2021): Closing this issue. Seems stale.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/asynq#1079
No description provided.