[GH-ISSUE #261] [FEATURE REQUEST] Ability to cancel pending tasks via inspeq #2122

Closed
opened 2026-03-15 19:16:16 +03:00 by kerem · 3 comments
Owner

Originally created by @f-ld on GitHub (Apr 7, 2021).
Original GitHub issue: https://github.com/hibiken/asynq/issues/261

Originally assigned to: @hibiken on GitHub.

Is your feature request related to a problem? Please describe.
We use asynq to queue tasks to be handled by a pool of handlers.
For some reason, me might have a lot of tasks queued (for a bug, a stress test, ...) and we would like to be able, for example from the inspector, to cancel them

Describe the solution you'd like
After getting some task ID running for example this:

$ asynq --uri 127.0.0.1:6379 --password foobar task ls --queue myqueue --state pending | head -n 4
ID                                    Type    Payload                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
--                                    ----    -------                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
8c28e228-168a-4f89-a41a-37d52532d9e3  type1 map[payload:Task1Payload]
22e23b7d-4861-43bc-a766-ea672db8c3d7  type1 map[payload:Task2Payload]

I would like to be able to run:

$ asynq --uri 127.0.0.1:6379 --password foobar task cancel 8c28e228-168a-4f89-a41a-37d52532d9e3,22e23b7d-4861-43bc-a766-ea672db8c3d7

to cancel a comma separated list of pending task from their IDs

Describe alternatives you've considered

  1. https://github.com/hibiken/asynq/wiki/Task-Timeout-and-Cancelation is only for cancelation of active tasks
  2. Use redis-cli and LREM to remove some elements from matching list or LTRIM in desperate conditions

Additional context
N/A

Originally created by @f-ld on GitHub (Apr 7, 2021). Original GitHub issue: https://github.com/hibiken/asynq/issues/261 Originally assigned to: @hibiken on GitHub. **Is your feature request related to a problem? Please describe.** We use asynq to queue tasks to be handled by a pool of handlers. For some reason, me might have a lot of tasks queued (for a bug, a stress test, ...) and we would like to be able, for example from the inspector, to cancel them **Describe the solution you'd like** After getting some task ID running for example this: ``` $ asynq --uri 127.0.0.1:6379 --password foobar task ls --queue myqueue --state pending | head -n 4 ID Type Payload -- ---- ------- 8c28e228-168a-4f89-a41a-37d52532d9e3 type1 map[payload:Task1Payload] 22e23b7d-4861-43bc-a766-ea672db8c3d7 type1 map[payload:Task2Payload] ``` I would like to be able to run: ``` $ asynq --uri 127.0.0.1:6379 --password foobar task cancel 8c28e228-168a-4f89-a41a-37d52532d9e3,22e23b7d-4861-43bc-a766-ea672db8c3d7 ``` to cancel a comma separated list of pending task from their IDs **Describe alternatives you've considered** 1. https://github.com/hibiken/asynq/wiki/Task-Timeout-and-Cancelation is only for cancelation of active tasks 2. Use `redis-cli` and `LREM` to remove some elements from matching list or `LTRIM` in desperate conditions **Additional context** N/A
kerem 2026-03-15 19:16:16 +03:00
Author
Owner

@hibiken commented on GitHub (Apr 7, 2021):

@f-ld Thank you for opening this issue.

By looking at the command output, it looks like you are using an older version of asynq package.

Deleting pending tasks is supported in the latest version, so if you could upgrade to the latest the following command is what you need:

asynq task ls --queue myqueue --state pending 
# Example output
#
# Key                                       Type   Payload
# ---                                       ----   -------
# p:5f99e65c-e634-4ce9-829b-2580628c61aa:0  test1  map[hello:world]

# delete task by key
asynq task delete --queue myqueue --key p:5f99e65c-e634-4ce9-829b-2580628c61aa:0

Alternative to the CLI tool is the Asynqmon Web UI.
Once you upgrade the package to the latest version, you should be able to use the Web UI to inspect the tasks in your queues.


Also, when you upgrade package version, please take a look at the CHANGELOG.
You may need to run asynq migrate command to migrate all existing tasks to work with the new package (it may be a good idea to create a backup in case the migration fails)

Please let me know if this doesn't work for you.

<!-- gh-comment-id:815142821 --> @hibiken commented on GitHub (Apr 7, 2021): @f-ld Thank you for opening this issue. By looking at the command output, it looks like you are using an older version of `asynq` package. Deleting pending tasks is supported in the latest version, so if you could upgrade to the latest the following command is what you need: ```bash asynq task ls --queue myqueue --state pending # Example output # # Key Type Payload # --- ---- ------- # p:5f99e65c-e634-4ce9-829b-2580628c61aa:0 test1 map[hello:world] # delete task by key asynq task delete --queue myqueue --key p:5f99e65c-e634-4ce9-829b-2580628c61aa:0 ``` Alternative to the CLI tool is the [Asynqmon](https://github.com/hibiken/asynqmon) Web UI. Once you upgrade the package to the latest version, you should be able to use the Web UI to inspect the tasks in your queues. ---- Also, when you upgrade package version, please take a look at the CHANGELOG. You may need to run `asynq migrate` command to migrate all existing tasks to work with the new package (it may be a good idea to create a backup in case the migration fails) Please let me know if this doesn't work for you.
Author
Owner

@hibiken commented on GitHub (Apr 13, 2021):

Closing this issue.
Feel free to re-open the issue if you still need assist 👍

<!-- gh-comment-id:818802525 --> @hibiken commented on GitHub (Apr 13, 2021): Closing this issue. Feel free to re-open the issue if you still need assist 👍
Author
Owner

@f-ld commented on GitHub (Apr 16, 2021):

Yes, sorry for the late reponse, running on various topics and this one is only one of them.
Using asynq 0.17.1 inspeq I could implement something cancelling obsolete task from queue (or cancel them and create new ones). That is super nice feature and module, thank you.

<!-- gh-comment-id:821314934 --> @f-ld commented on GitHub (Apr 16, 2021): Yes, sorry for the late reponse, running on various topics and this one is only one of them. Using asynq 0.17.1 inspeq I could implement something cancelling obsolete task from queue (or cancel them and create new ones). That is super nice feature and module, thank you.
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#2122
No description provided.