diff options
| author | nsfisis <nsfisis@gmail.com> | 2024-08-05 04:39:51 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2024-08-05 05:14:30 +0900 |
| commit | 1325626397703567828a903a82fc1ed8626dbad4 (patch) | |
| tree | d667f50894676a7bb208c03a7e96812ef0d029b9 | |
| parent | 940fc430a5c8fa7a1454cc84586eaca2722ac757 (diff) | |
| download | iosdc-japan-2024-albatross-1325626397703567828a903a82fc1ed8626dbad4.tar.gz iosdc-japan-2024-albatross-1325626397703567828a903a82fc1ed8626dbad4.tar.zst iosdc-japan-2024-albatross-1325626397703567828a903a82fc1ed8626dbad4.zip | |
feat(backend): enqueue exec task when players submit their code
| -rw-r--r-- | backend/game/hub.go | 8 | ||||
| -rw-r--r-- | backend/taskqueue/tasks.go | 17 |
2 files changed, 13 insertions, 12 deletions
diff --git a/backend/game/hub.go b/backend/game/hub.go index a44bce0..0b12ce9 100644 --- a/backend/game/hub.go +++ b/backend/game/hub.go @@ -176,8 +176,12 @@ func (hub *gameHub) run() { case *playerMessageC2SSubmit: // TODO: assert game state is gaming log.Printf("submit: %v", message.message) - // code := msg.Data.Code - // TODO + code := msg.Data.Code + task, err := taskqueue.NewExecTask(hub.game.gameID, message.client.playerID, code) + if err != nil { + log.Fatalf("failed to create task: %v", err) + } + hub.taskQueue.Enqueue(task) default: log.Printf("unexpected message type: %T", message.message) } diff --git a/backend/taskqueue/tasks.go b/backend/taskqueue/tasks.go index 2891a36..cd67948 100644 --- a/backend/taskqueue/tasks.go +++ b/backend/taskqueue/tasks.go @@ -10,20 +10,17 @@ const ( TaskTypeExec = "exec" ) -type Testcase struct { - Stdin string - Stdout string -} - type TaskExecPlayload struct { - Code string - Testcases []*Testcase + GameID int + UserID int + Code string } -func NewExecTask(code string, testcases []*Testcase) (*asynq.Task, error) { +func NewExecTask(gameID, userID int, code string) (*asynq.Task, error) { payload, err := json.Marshal(TaskExecPlayload{ - Code: code, - Testcases: testcases, + GameID: gameID, + UserID: userID, + Code: code, }) if err != nil { return nil, err |
