diff options
| author | nsfisis <nsfisis@gmail.com> | 2025-03-04 22:55:01 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2025-03-08 10:12:44 +0900 |
| commit | 1e6df136d8202c8adf65948527f4c3e7583b338c (patch) | |
| tree | 7c82476f6bbbc71d72ab7e71e39559eca197fd95 /backend/taskqueue/tasks.go | |
| parent | 54316868c3bec1ff9b04643dfe6c13cf56bf3246 (diff) | |
| download | iosdc-japan-2025-albatross-1e6df136d8202c8adf65948527f4c3e7583b338c.tar.gz iosdc-japan-2025-albatross-1e6df136d8202c8adf65948527f4c3e7583b338c.tar.zst iosdc-japan-2025-albatross-1e6df136d8202c8adf65948527f4c3e7583b338c.zip | |
websocket to polling
Diffstat (limited to 'backend/taskqueue/tasks.go')
| -rw-r--r-- | backend/taskqueue/tasks.go | 162 |
1 files changed, 9 insertions, 153 deletions
diff --git a/backend/taskqueue/tasks.go b/backend/taskqueue/tasks.go index d5f2993..e595d99 100644 --- a/backend/taskqueue/tasks.go +++ b/backend/taskqueue/tasks.go @@ -8,121 +8,16 @@ import ( type TaskType string -// MD5 hash in hexadecimal format -type MD5HexHash string - const ( - TaskTypeCreateSubmissionRecord TaskType = "create_submission_record" - TaskTypeCompileSwiftToWasm TaskType = "compile_swift_to_wasm" - TaskTypeCompileWasmToNativeExecutable TaskType = "compile_wasm_to_native_executable" - TaskTypeRunTestcase TaskType = "run_testcase" + TaskTypeRunTestcase TaskType = "run_testcase" ) -type TaskPayloadBase struct { - GameID int - UserID int - CodeHash MD5HexHash -} - -type TaskPayloadCreateSubmissionRecord struct { - TaskPayloadBase - Code string - CodeSize int -} - -func newTaskCreateSubmissionRecord( - gameID int, - userID int, - code string, - codeSize int, - codeHash MD5HexHash, -) (*asynq.Task, error) { - payload, err := json.Marshal(TaskPayloadCreateSubmissionRecord{ - TaskPayloadBase: TaskPayloadBase{ - GameID: gameID, - UserID: userID, - CodeHash: codeHash, - }, - Code: code, - CodeSize: codeSize, - }) - if err != nil { - return nil, err - } - return asynq.NewTask(string(TaskTypeCreateSubmissionRecord), payload), nil -} - -func (t *TaskPayloadCreateSubmissionRecord) GameID() int { return t.TaskPayloadBase.GameID } -func (t *TaskPayloadCreateSubmissionRecord) UserID() int { return t.TaskPayloadBase.UserID } -func (t *TaskPayloadCreateSubmissionRecord) CodeHash() MD5HexHash { return t.TaskPayloadBase.CodeHash } - -type TaskPayloadCompileSwiftToWasm struct { - TaskPayloadBase - SubmissionID int - Code string -} - -func newTaskCompileSwiftToWasm( - gameID int, - userID int, - code string, - codeHash MD5HexHash, - submissionID int, -) (*asynq.Task, error) { - payload, err := json.Marshal(TaskPayloadCompileSwiftToWasm{ - TaskPayloadBase: TaskPayloadBase{ - GameID: gameID, - UserID: userID, - CodeHash: codeHash, - }, - SubmissionID: submissionID, - Code: code, - }) - if err != nil { - return nil, err - } - return asynq.NewTask(string(TaskTypeCompileSwiftToWasm), payload), nil -} - -func (t *TaskPayloadCompileSwiftToWasm) GameID() int { return t.TaskPayloadBase.GameID } -func (t *TaskPayloadCompileSwiftToWasm) UserID() int { return t.TaskPayloadBase.UserID } -func (t *TaskPayloadCompileSwiftToWasm) CodeHash() MD5HexHash { return t.TaskPayloadBase.CodeHash } - -type TaskPayloadCompileWasmToNativeExecutable struct { - TaskPayloadBase - SubmissionID int -} - -func newTaskCompileWasmToNativeExecutable( - gameID int, - userID int, - codeHash MD5HexHash, - submissionID int, -) (*asynq.Task, error) { - payload, err := json.Marshal(TaskPayloadCompileWasmToNativeExecutable{ - TaskPayloadBase: TaskPayloadBase{ - GameID: gameID, - UserID: userID, - CodeHash: codeHash, - }, - SubmissionID: submissionID, - }) - if err != nil { - return nil, err - } - return asynq.NewTask(string(TaskTypeCompileWasmToNativeExecutable), payload), nil -} - -func (t *TaskPayloadCompileWasmToNativeExecutable) GameID() int { return t.TaskPayloadBase.GameID } -func (t *TaskPayloadCompileWasmToNativeExecutable) UserID() int { return t.TaskPayloadBase.UserID } -func (t *TaskPayloadCompileWasmToNativeExecutable) CodeHash() MD5HexHash { - return t.TaskPayloadBase.CodeHash -} - type TaskPayloadRunTestcase struct { - TaskPayloadBase + GameID int + UserID int SubmissionID int TestcaseID int + Code string Stdin string Stdout string } @@ -130,20 +25,18 @@ type TaskPayloadRunTestcase struct { func newTaskRunTestcase( gameID int, userID int, - codeHash MD5HexHash, submissionID int, testcaseID int, + code string, stdin string, stdout string, ) (*asynq.Task, error) { payload, err := json.Marshal(TaskPayloadRunTestcase{ - TaskPayloadBase: TaskPayloadBase{ - GameID: gameID, - UserID: userID, - CodeHash: codeHash, - }, + GameID: gameID, + UserID: userID, SubmissionID: submissionID, TestcaseID: testcaseID, + Code: code, Stdin: stdin, Stdout: stdout, }) @@ -153,48 +46,11 @@ func newTaskRunTestcase( return asynq.NewTask(string(TaskTypeRunTestcase), payload), nil } -func (t *TaskPayloadRunTestcase) GameID() int { return t.TaskPayloadBase.GameID } -func (t *TaskPayloadRunTestcase) UserID() int { return t.TaskPayloadBase.UserID } -func (t *TaskPayloadRunTestcase) CodeHash() MD5HexHash { return t.TaskPayloadBase.CodeHash } - type TaskResult interface { Type() TaskType GameID() int } -type TaskResultCreateSubmissionRecord struct { - TaskPayload *TaskPayloadCreateSubmissionRecord - SubmissionID int - Err error -} - -func (r *TaskResultCreateSubmissionRecord) Type() TaskType { return TaskTypeCreateSubmissionRecord } -func (r *TaskResultCreateSubmissionRecord) GameID() int { return r.TaskPayload.GameID() } - -type TaskResultCompileSwiftToWasm struct { - TaskPayload *TaskPayloadCompileSwiftToWasm - Status string - Stdout string - Stderr string - Err error -} - -func (r *TaskResultCompileSwiftToWasm) Type() TaskType { return TaskTypeCompileSwiftToWasm } -func (r *TaskResultCompileSwiftToWasm) GameID() int { return r.TaskPayload.GameID() } - -type TaskResultCompileWasmToNativeExecutable struct { - TaskPayload *TaskPayloadCompileWasmToNativeExecutable - Status string - Stdout string - Stderr string - Err error -} - -func (r *TaskResultCompileWasmToNativeExecutable) Type() TaskType { - return TaskTypeCompileWasmToNativeExecutable -} -func (r *TaskResultCompileWasmToNativeExecutable) GameID() int { return r.TaskPayload.GameID() } - type TaskResultRunTestcase struct { TaskPayload *TaskPayloadRunTestcase Status string @@ -204,4 +60,4 @@ type TaskResultRunTestcase struct { } func (r *TaskResultRunTestcase) Type() TaskType { return TaskTypeRunTestcase } -func (r *TaskResultRunTestcase) GameID() int { return r.TaskPayload.GameID() } +func (r *TaskResultRunTestcase) GameID() int { return r.TaskPayload.GameID } |
