[GH-ISSUE #335] [QUESTION] How does registration and execution of task works with scheduler? #145

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

Originally created by @sujit-baniya on GitHub (Oct 24, 2021).
Original GitHub issue: https://github.com/hibiken/asynq/issues/335

Originally assigned to: @hibiken on GitHub.

For a normal task, we need to create handler and assign queue to that handler (if we use mux). So whenever task is enqueued, handler processes the task.

But for scheduled task, as per this: https://github.com/hibiken/asynq/wiki/Periodic-Tasks
I don't see we define the handler for the task. So please help me understand, when I register a task

task := asynq.NewTask("example_task", nil)
entryID, err := scheduler.Register("* * * * *", task)
if err != nil {
    log.Fatal(err)
}
log.Printf("registered an entry: %q\n", entryID)

How is this task executed? Which handler executes this task?

Originally created by @sujit-baniya on GitHub (Oct 24, 2021). Original GitHub issue: https://github.com/hibiken/asynq/issues/335 Originally assigned to: @hibiken on GitHub. For a normal task, we need to create handler and assign queue to that handler (if we use mux). So whenever task is enqueued, handler processes the task. But for scheduled task, as per this: https://github.com/hibiken/asynq/wiki/Periodic-Tasks I don't see we define the handler for the task. So please help me understand, when I register a task ```go task := asynq.NewTask("example_task", nil) entryID, err := scheduler.Register("* * * * *", task) if err != nil { log.Fatal(err) } log.Printf("registered an entry: %q\n", entryID) ``` How is this task executed? Which handler executes this task?
kerem 2026-03-02 05:19:07 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@crossworth commented on GitHub (Oct 24, 2021):

Hello, the task handler for the task, when you use the scheduler you are "only chaning the way" the task get put on the queue.

See this comment for more info: https://github.com/hibiken/asynq/issues/308#issuecomment-893711883

<!-- gh-comment-id:950357108 --> @crossworth commented on GitHub (Oct 24, 2021): Hello, the task handler for the task, when you use the scheduler you are "only chaning the way" the task get put on the queue. See this comment for more info: https://github.com/hibiken/asynq/issues/308#issuecomment-893711883
Author
Owner

@sujit-baniya commented on GitHub (Oct 24, 2021):

@crossworth So it means, I have to create queue (by default default queue is used) and handler for this queue on server. Start the scheduler then register the scheduled task to the queue

robfig/cron will pick the task and Enqueue to the provided queue at that specific time period, right?

If that's the case, then maybe need to update the wiki: https://github.com/hibiken/asynq/wiki/Periodic-Tasks with full example?

<!-- gh-comment-id:950357753 --> @sujit-baniya commented on GitHub (Oct 24, 2021): @crossworth So it means, I have to create queue (by default `default` queue is used) and handler for this queue on server. Start the scheduler then register the scheduled task to the queue robfig/cron will pick the task and `Enqueue` to the provided queue at that specific time period, right? If that's the case, then maybe need to update the wiki: https://github.com/hibiken/asynq/wiki/Periodic-Tasks with full example?
Author
Owner

@crossworth commented on GitHub (Oct 24, 2021):

Yes, at least for the current implementation.

<!-- gh-comment-id:950357997 --> @crossworth commented on GitHub (Oct 24, 2021): Yes, at least for the current implementation.
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#145
No description provided.