aboutsummaryrefslogtreecommitdiffhomepage
path: root/backend/taskqueue/queue.go
blob: 60844d2b1d4d0484b7d30954ee78cb080e601254 (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
42
43
44
45
46
47
48
package taskqueue

import (
	"github.com/hibiken/asynq"
)

type Queue struct {
	client *asynq.Client
}

func NewQueue(redisAddr string) *Queue {
	return &Queue{
		client: asynq.NewClient(asynq.RedisClientOpt{
			Addr: redisAddr,
		}),
	}
}

func (q *Queue) Close() {
	q.client.Close()
}

func (q *Queue) EnqueueTaskRunTestcase(
	gameID int,
	userID int,
	submissionID int,
	testcaseID int,
	language string,
	code string,
	stdin string,
	stdout string,
) error {
	task, err := newTaskRunTestcase(
		gameID,
		userID,
		submissionID,
		testcaseID,
		language,
		code,
		stdin,
		stdout,
	)
	if err != nil {
		return err
	}
	_, err = q.client.Enqueue(task)
	return err
}