golang-queue-test/cmd/worker/main.go
2025-05-05 09:25:43 +02:00

35 lines
716 B
Go

package main
import (
"log"
"github.com/hibiken/asynq"
"gitnet.fr/deblan/golang-worker/task/foo"
)
const redisAddr = "127.0.0.1:6379"
func main() {
srv := asynq.NewServer(
asynq.RedisClientOpt{Addr: redisAddr},
asynq.Config{
// Specify how many concurrent workers to use
Concurrency: 10,
// Optionally specify multiple queues with different priority.
Queues: map[string]int{
"critical": 6,
"default": 3,
"low": 1,
},
// See the godoc for other configuration options
},
)
// mux maps a type to a handler
mux := asynq.NewServeMux()
mux.HandleFunc("foo", foo.HandleFooTask)
if err := srv.Run(mux); err != nil {
log.Fatalf("could not run server: %v", err)
}
}