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

import (
	"encoding/json"

	"github.com/hibiken/asynq"
)

const (
	TaskTypeExec = "exec"
)

type TaskExecPlayload struct {
	GameID int
	UserID int
	Code   string
}

func NewExecTask(gameID, userID int, code string) (*asynq.Task, error) {
	payload, err := json.Marshal(TaskExecPlayload{
		GameID: gameID,
		UserID: userID,
		Code:   code,
	})
	if err != nil {
		return nil, err
	}
	return asynq.NewTask(TaskTypeExec, payload), nil
}