aboutsummaryrefslogtreecommitdiffhomepage
path: root/backend/taskqueue/worker_server.go
blob: 485d6d39e3fe44db67e04f50de075c08cc99958d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package taskqueue

import (
	"github.com/hibiken/asynq"

	"github.com/nsfisis/iosdc-japan-2024-albatross/backend/db"
)

type WorkerServer struct {
	server  *asynq.Server
	queries *db.Queries
	c       chan string
}

func NewWorkerServer(redisAddr string, queries *db.Queries, c chan string) *WorkerServer {
	return &WorkerServer{
		server: asynq.NewServer(
			asynq.RedisClientOpt{
				Addr: redisAddr,
			},
			asynq.Config{},
		),
		queries: queries,
		c:       c,
	}
}

func (s *WorkerServer) Run() error {
	mux := asynq.NewServeMux()
	mux.Handle(TaskTypeExec, NewExecProcessor(s.queries, s.c))

	return s.server.Run(mux)
}