blob: 67803e21952b061abbee12bddca0351a3e88b11a (
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
34
35
36
37
|
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
results chan TaskExecResult
}
func NewWorkerServer(redisAddr string, queries *db.Queries) *WorkerServer {
return &WorkerServer{
server: asynq.NewServer(
asynq.RedisClientOpt{
Addr: redisAddr,
},
asynq.Config{},
),
queries: queries,
results: make(chan TaskExecResult),
}
}
func (s *WorkerServer) Run() error {
mux := asynq.NewServeMux()
mux.Handle(TaskTypeExec, NewExecProcessor(s.queries, s.results))
return s.server.Run(mux)
}
func (s *WorkerServer) Results() chan TaskExecResult {
return s.results
}
|