hibiken / asynq

Simple, reliable, and efficient distributed task queue in Go
MIT License
10.04k stars 716 forks source link

[BUG] Unable to schedule a task #881

Closed noloman closed 6 months ago

noloman commented 6 months ago

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
kamikazechaser commented 6 months ago

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