aboutsummaryrefslogtreecommitdiffhomepage
path: root/backend/taskqueue/worker_server.go
blob: 51387d1520db0f91b729b71861910df8c0150e8e (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
38
39
40
41
package taskqueue

import (
	"github.com/hibiken/asynq"

	"github.com/nsfisis/phperkaigi-2025-albatross/backend/db"
)

type WorkerServer struct {
	server    *asynq.Server
	processor *processorWrapper
}

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

func (s *WorkerServer) Run() error {
	mux := asynq.NewServeMux()

	mux.HandleFunc(string(TaskTypeCreateSubmissionRecord), s.processor.processTaskCreateSubmissionRecord)
	mux.HandleFunc(string(TaskTypeCompileSwiftToWasm), s.processor.processTaskCompileSwiftToWasm)
	mux.HandleFunc(string(TaskTypeCompileWasmToNativeExecutable), s.processor.processTaskCompileWasmToNativeExecutable)
	mux.HandleFunc(string(TaskTypeRunTestcase), s.processor.processTaskRunTestcase)

	return s.server.Run(mux)
}

func (s *WorkerServer) Results() chan TaskResult {
	return s.processor.results
}