[GH-ISSUE #881] [BUG] Unable to schedule a task #433

Closed
opened 2026-03-02 05:21:10 +03:00 by kerem · 1 comment
Owner

Originally created by @noloman on GitHub (May 5, 2024).
Original GitHub issue: https://github.com/hibiken/asynq/issues/881

Originally assigned to: @hibiken on GitHub.

Describe the bug
I'm trying to schedule a task to be run every 5 minutes for testing purposes and nothing is happening.

To Reproduce

func scheduleBackgroundJobs(app *application) {
	netherlands, err := time.LoadLocation("Europe/Amsterdam")
	if err != nil {
		app.logger.Error("could not load location: %v", err)
	}
	redisConnOpt := asynq.RedisClientOpt{Addr: app.config.redisAddr, Password: "mytestpass"}
	scheduler := asynq.NewScheduler(redisConnOpt, &asynq.SchedulerOpts{
		Location: netherlands,
	})

	client := asynq.NewClient(redisConnOpt)
	defer client.Close()

	jobsUpdateTask, err := app.jobsUpdateTask.NewJobsUpdateTask()
	if err != nil {
		app.logger.Error("could not create task: %v", err)
	}

	entryID, err := scheduler.Register("*/5 * * * *", jobsUpdateTask)
	if err != nil {
		app.logger.Error("Error scheduling task: %v", err)
	}
	app.logger.Info("registered an entry: %q\n", entryID)

	if err := scheduler.Run(); err != nil {
		app.logger.Error("Error running scheduler: %v", err)
	}
}

However I see nothing being scheduled in the console (while before, I used client.enqueue and it worked).
Running asynq dash -p shows the scheduled tasks in pending:

Screenshot 2024-05-05 at 12 42 46 Screenshot 2024-05-05 at 12 43 12
Originally created by @noloman on GitHub (May 5, 2024). Original GitHub issue: https://github.com/hibiken/asynq/issues/881 Originally assigned to: @hibiken on GitHub. **Describe the bug** I'm trying to schedule a task to be run every 5 minutes for testing purposes and nothing is happening. **To Reproduce** ```go func scheduleBackgroundJobs(app *application) { netherlands, err := time.LoadLocation("Europe/Amsterdam") if err != nil { app.logger.Error("could not load location: %v", err) } redisConnOpt := asynq.RedisClientOpt{Addr: app.config.redisAddr, Password: "mytestpass"} scheduler := asynq.NewScheduler(redisConnOpt, &asynq.SchedulerOpts{ Location: netherlands, }) client := asynq.NewClient(redisConnOpt) defer client.Close() jobsUpdateTask, err := app.jobsUpdateTask.NewJobsUpdateTask() if err != nil { app.logger.Error("could not create task: %v", err) } entryID, err := scheduler.Register("*/5 * * * *", jobsUpdateTask) if err != nil { app.logger.Error("Error scheduling task: %v", err) } app.logger.Info("registered an entry: %q\n", entryID) if err := scheduler.Run(); err != nil { app.logger.Error("Error running scheduler: %v", err) } } ``` However I see nothing being scheduled in the console (while before, I used `client.enqueue` and it worked). Running `asynq dash -p` shows the scheduled tasks in pending: <img width="781" alt="Screenshot 2024-05-05 at 12 42 46" src="https://github.com/hibiken/asynq/assets/183264/9f178371-135b-48d1-8116-408afaf29cdc"> <img width="891" alt="Screenshot 2024-05-05 at 12 43 12" src="https://github.com/hibiken/asynq/assets/183264/02929d75-7edb-41d5-afe0-6f9c64842e5f">
kerem 2026-03-02 05:21:10 +03:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@kamikazechaser commented on GitHub (May 6, 2024):

You need to run the Server alongside the Scheduler as described in the wiki. The server provisions workers.

<!-- gh-comment-id:2095244862 --> @kamikazechaser commented on GitHub (May 6, 2024): You need to run the [`Server`](https://pkg.go.dev/github.com/hibiken/asynq#Server) alongside the `Scheduler` as described in the wiki. The server provisions workers.
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#433
No description provided.