aboutsummaryrefslogtreecommitdiffhomepage
path: root/backend/taskqueue/tasks.go
blob: 2891a361cb880da17831e87de713bc00487fd4ce (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
package taskqueue

import (
	"encoding/json"

	"github.com/hibiken/asynq"
)

const (
	TaskTypeExec = "exec"
)

type Testcase struct {
	Stdin  string
	Stdout string
}

type TaskExecPlayload struct {
	Code      string
	Testcases []*Testcase
}

func NewExecTask(code string, testcases []*Testcase) (*asynq.Task, error) {
	payload, err := json.Marshal(TaskExecPlayload{
		Code:      code,
		Testcases: testcases,
	})
	if err != nil {
		return nil, err
	}
	return asynq.NewTask(TaskTypeExec, payload), nil
}