[GH-ISSUE #69] [FEATURE REQUEST] Make handler context aware #1032

Closed
opened 2026-03-07 22:04:15 +03:00 by kerem · 0 comments
Owner

Originally created by @hibiken on GitHub (Jan 30, 2020).
Original GitHub issue: https://github.com/hibiken/asynq/issues/69

Originally assigned to: @hibiken on GitHub.

We should support timeout per task and allow user to cancel task processing using the CLI.

Cancellation would be useful in two cases:

  • User manually cancels a in-progress task using the CLI
  • Background worker process is shutting down, so in-progress tasks should be cancelled

Optional timeout per task is used in cases such as:

  • For tasks that are best-effort. If processing could not complete within a certain timeout, bail and retry later.

In order to support both cancel and timeout, we need to change the Handler interface.

type Handler interface {
    func ProcessTask(ctx context.Context, t *Task) error
}

and add Timeout function to create a timeout option when scheduling a task.

client.Schedule(task, time.Now().Add(time.Hour), asynq.Timeout(10 * time.Second))

CLI will have a new command to cancel a in-progress task:

asynqmon cancel [task_id]

A cancelled task should be moved to retry state consuming a retry count.

Originally created by @hibiken on GitHub (Jan 30, 2020). Original GitHub issue: https://github.com/hibiken/asynq/issues/69 Originally assigned to: @hibiken on GitHub. We should support timeout per task and allow user to cancel task processing using the CLI. Cancellation would be useful in two cases: - User manually cancels a in-progress task using the CLI - Background worker process is shutting down, so in-progress tasks should be cancelled Optional timeout per task is used in cases such as: - For tasks that are best-effort. If processing could not complete within a certain timeout, bail and retry later. In order to support both cancel and timeout, we need to change the `Handler` interface. ```go type Handler interface { func ProcessTask(ctx context.Context, t *Task) error } ``` and add `Timeout` function to create a timeout option when scheduling a task. ```go client.Schedule(task, time.Now().Add(time.Hour), asynq.Timeout(10 * time.Second)) ``` CLI will have a new command to cancel a in-progress task: ```sh asynqmon cancel [task_id] ``` A cancelled task should be moved to *retry* state consuming a retry count.
kerem 2026-03-07 22:04:15 +03:00
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#1032
No description provided.