diff options
| author | nsfisis <nsfisis@gmail.com> | 2024-08-07 22:14:51 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2024-08-08 04:02:37 +0900 |
| commit | 6bb6071ec1dce0cce59df0cb1c38168918061041 (patch) | |
| tree | feca06471f51ac5a1cdaaed4a0333ee9c0cf38e3 /backend/taskqueue/processor.go | |
| parent | 401a28944fc0408811aedadd1c3104e2e2d4d7fe (diff) | |
| download | iosdc-japan-2025-albatross-6bb6071ec1dce0cce59df0cb1c38168918061041.tar.gz iosdc-japan-2025-albatross-6bb6071ec1dce0cce59df0cb1c38168918061041.tar.zst iosdc-japan-2025-albatross-6bb6071ec1dce0cce59df0cb1c38168918061041.zip | |
refactor(backend): move ownership of channel to send task results
Diffstat (limited to 'backend/taskqueue/processor.go')
| -rw-r--r-- | backend/taskqueue/processor.go | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/backend/taskqueue/processor.go b/backend/taskqueue/processor.go index 1d4c412..ca180e9 100644 --- a/backend/taskqueue/processor.go +++ b/backend/taskqueue/processor.go @@ -14,14 +14,14 @@ import ( ) type ExecProcessor struct { - q *db.Queries - c chan string + q *db.Queries + results chan TaskExecResult } -func NewExecProcessor(q *db.Queries, c chan string) *ExecProcessor { +func NewExecProcessor(q *db.Queries, results chan TaskExecResult) *ExecProcessor { return &ExecProcessor{ - q: q, - c: c, + q: q, + results: results, } } @@ -80,7 +80,10 @@ func (p *ExecProcessor) ProcessTask(ctx context.Context, t *asynq.Task) error { if err != nil { return fmt.Errorf("CreateTestcaseExecution failed: %v", err) } - p.c <- "compile_error" + p.results <- TaskExecResult{ + Task: &payload, + Result: "compile_error", + } return fmt.Errorf("swiftc failed: %v", resData.Stderr) } } @@ -121,7 +124,10 @@ func (p *ExecProcessor) ProcessTask(ctx context.Context, t *asynq.Task) error { if err != nil { return fmt.Errorf("CreateTestcaseExecution failed: %v", err) } - p.c <- "compile_error" + p.results <- TaskExecResult{ + Task: &payload, + Result: "compile_error", + } return fmt.Errorf("wasmc failed: %v", resData.Stderr) } } @@ -170,7 +176,10 @@ func (p *ExecProcessor) ProcessTask(ctx context.Context, t *asynq.Task) error { if err != nil { return fmt.Errorf("CreateTestcaseExecution failed: %v", err) } - p.c <- resData.Result + p.results <- TaskExecResult{ + Task: &payload, + Result: resData.Result, + } return fmt.Errorf("testrun failed: %v", resData.Stderr) } if !isTestcaseExecutionCorrect(testcase.Stdout, resData.Stdout) { @@ -184,12 +193,18 @@ func (p *ExecProcessor) ProcessTask(ctx context.Context, t *asynq.Task) error { if err != nil { return fmt.Errorf("CreateTestcaseExecution failed: %v", err) } - p.c <- "wrong_answer" + p.results <- TaskExecResult{ + Task: &payload, + Result: "wrong_answer", + } return fmt.Errorf("testrun failed: %v", resData.Stdout) } } - p.c <- "success" + p.results <- TaskExecResult{ + Task: &payload, + Result: "success", + } return nil } |
