diff options
| author | nsfisis <nsfisis@gmail.com> | 2024-08-05 05:35:45 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2024-08-05 05:35:45 +0900 |
| commit | b0ff29a3c88bd3014cc966c619683c8d7e33d703 (patch) | |
| tree | 529f1debc2972ac1486e8c0ca4b25827ccd069a6 | |
| parent | 9ff9c151e5defd9eed5cba3c88bc341b4360d09c (diff) | |
| parent | dc16e903999af89d87364ad6619e7c8b41301da4 (diff) | |
| download | iosdc-japan-2024-albatross-b0ff29a3c88bd3014cc966c619683c8d7e33d703.tar.gz iosdc-japan-2024-albatross-b0ff29a3c88bd3014cc966c619683c8d7e33d703.tar.zst iosdc-japan-2024-albatross-b0ff29a3c88bd3014cc966c619683c8d7e33d703.zip | |
Merge branch 'feat/task-queue'
| -rw-r--r-- | backend/api/generated.go | 58 | ||||
| -rw-r--r-- | backend/db/models.go | 18 | ||||
| -rw-r--r-- | backend/db/query.sql.go | 79 | ||||
| -rw-r--r-- | backend/fixtures/dev.sql | 5 | ||||
| -rw-r--r-- | backend/game/hub.go | 43 | ||||
| -rw-r--r-- | backend/go.mod | 14 | ||||
| -rw-r--r-- | backend/go.sum | 63 | ||||
| -rw-r--r-- | backend/main.go | 10 | ||||
| -rw-r--r-- | backend/query.sql | 13 | ||||
| -rw-r--r-- | backend/schema.sql | 23 | ||||
| -rw-r--r-- | backend/taskqueue/processor.go | 199 | ||||
| -rw-r--r-- | backend/taskqueue/queue.go | 25 | ||||
| -rw-r--r-- | backend/taskqueue/tasks.go | 29 | ||||
| -rw-r--r-- | backend/taskqueue/worker_server.go | 33 | ||||
| -rw-r--r-- | compose.local.yaml | 13 | ||||
| -rw-r--r-- | frontend/app/.server/api/schema.d.ts | 2 | ||||
| -rw-r--r-- | frontend/app/components/GolfPlayApp.client.tsx | 6 | ||||
| -rw-r--r-- | frontend/app/components/GolfPlayApps/GolfPlayAppGaming.tsx | 5 | ||||
| -rw-r--r-- | openapi.yaml | 5 |
19 files changed, 592 insertions, 51 deletions
diff --git a/backend/api/generated.go b/backend/api/generated.go index e371c7d..3c52f84 100644 --- a/backend/api/generated.go +++ b/backend/api/generated.go @@ -41,7 +41,12 @@ const ( // Defines values for GamePlayerMessageS2CExecResultPayloadStatus. const ( - GamePlayerMessageS2CExecResultPayloadStatusSuccess GamePlayerMessageS2CExecResultPayloadStatus = "success" + GamePlayerMessageS2CExecResultPayloadStatusCompileError GamePlayerMessageS2CExecResultPayloadStatus = "compile_error" + GamePlayerMessageS2CExecResultPayloadStatusFailure GamePlayerMessageS2CExecResultPayloadStatus = "failure" + GamePlayerMessageS2CExecResultPayloadStatusInternalError GamePlayerMessageS2CExecResultPayloadStatus = "internal_error" + GamePlayerMessageS2CExecResultPayloadStatusSuccess GamePlayerMessageS2CExecResultPayloadStatus = "success" + GamePlayerMessageS2CExecResultPayloadStatusTimeout GamePlayerMessageS2CExecResultPayloadStatus = "timeout" + GamePlayerMessageS2CExecResultPayloadStatusWrongAnswer GamePlayerMessageS2CExecResultPayloadStatus = "wrong_answer" ) // Defines values for GameWatcherMessageS2CExecResultPayloadStatus. @@ -1101,31 +1106,32 @@ func (sh *strictHandler) GetToken(ctx echo.Context, params GetTokenParams) error // Base64 encoded, gzipped, json marshaled Swagger object var swaggerSpec = []string{ - "H4sIAAAAAAAC/9xZbW/bNhD+Kxo3oBug+S1B0flbmrVZh64z6hb7UAQGLZ1tZhKpklQSL9B/H0jqxbQo", - "S3aUrFg+BLbEu3vu7uHxfHxAAYsTRoFKgaYPKMEcxyCB628bwCHwBU7lhnHyD5aEUfWcUDTNXyIfURwD", - "mqILa5WPOHxNCYcQTSVPwUci2ECMlbjcJkpASE7oGmWZjxIsN4s1jmFBwtKAelipL952UEyohDVwlCnV", - "HETCqADt0GscfoSvKQipvgWMSqD6I06SiAQa+vBGGC8rvT9wWKEp+n5YBWto3orhG85ZbioEEXCSmCgp", - "Wx7PjWU+esv4koQh0Ke3XJnKfPSBybcspeHTm/3ApLfSpjIffaYFa+AZTFv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gUgblL4xgDfPgavIOhegehLSn44PesDfQ6HkKDKcEjdFFb9AbIHvxYlLUX+LE", + "JmsJZjvo/JkzyncxGqMbUDdmQehcEe0ZiOol/dYrpPx2515mNBicdEng0quCThQk0qda1QUJYSHwpvU0", + "V+7Jgnv18J5IFfBFYCXyEF0OhvsgVD733QsLLXRxXGjrXkc3kixJsNiUEAr7eViksv9YnEjnx5LaUU7D", + "o3LOLd8TcMAv8y2Z9kr0lQnxs2VYS1wel6iu91xK3IAKcAFYU4Lypa2GKZctTJhwqd6bJTY4INVrbo86", + "z8xHiqVccxHvzNvF0+Hooq1sf2N1ZSWZC9PtWXWvj/NOWaj437DT1B/0X2/r//E5xyjxoeTUjqOLjNJN", + "oOkGTGmoJeNOpqnDId3LA0scw6HKuX3F5JNZ8D12iP9UXuzelisu1M+U3EMcYGMusADzPM//DQAA///+", + "G+PQ1yEAAA==", } // GetSwagger returns the content of the embedded swagger specification file diff --git a/backend/db/models.go b/backend/db/models.go index 51157bc..431d860 100644 --- a/backend/db/models.go +++ b/backend/db/models.go @@ -30,6 +30,15 @@ type Problem struct { Description string } +type Submission struct { + SubmissionID int32 + GameID int32 + UserID int32 + Code string + CodeSize int32 + CreatedAt pgtype.Timestamp +} + type Testcase struct { TestcaseID int32 ProblemID int32 @@ -37,6 +46,15 @@ type Testcase struct { Stdout string } +type TestcaseExecution struct { + TestcaseExecutionID int32 + SubmissionID int32 + TestcaseID *int32 + Status string + Stdout string + Stderr string +} + type User struct { UserID int32 Username string diff --git a/backend/db/query.sql.go b/backend/db/query.sql.go index 8df3bf5..89506d0 100644 --- a/backend/db/query.sql.go +++ b/backend/db/query.sql.go @@ -11,6 +11,55 @@ import ( "github.com/jackc/pgx/v5/pgtype" ) +const createSubmission = `-- name: CreateSubmission :one +INSERT INTO submissions (game_id, user_id, code, code_size) +VALUES ($1, $2, $3, $4) +RETURNING submission_id +` + +type CreateSubmissionParams struct { + GameID int32 + UserID int32 + Code string + CodeSize int32 +} + +func (q *Queries) CreateSubmission(ctx context.Context, arg CreateSubmissionParams) (int32, error) { + row := q.db.QueryRow(ctx, createSubmission, + arg.GameID, + arg.UserID, + arg.Code, + arg.CodeSize, + ) + var submission_id int32 + err := row.Scan(&submission_id) + return submission_id, err +} + +const createTestcaseExecution = `-- name: CreateTestcaseExecution :exec +INSERT INTO testcase_executions (submission_id, testcase_id, status, stdout, stderr) +VALUES ($1, $2, $3, $4, $5) +` + +type CreateTestcaseExecutionParams struct { + SubmissionID int32 + TestcaseID *int32 + Status string + Stdout string + Stderr string +} + +func (q *Queries) CreateTestcaseExecution(ctx context.Context, arg CreateTestcaseExecutionParams) error { + _, err := q.db.Exec(ctx, createTestcaseExecution, + arg.SubmissionID, + arg.TestcaseID, + arg.Status, + arg.Stdout, + arg.Stderr, + ) + return err +} + const getGameByID = `-- name: GetGameByID :one SELECT game_id, game_type, state, display_name, duration_seconds, created_at, started_at, games.problem_id, problems.problem_id, title, description FROM games LEFT JOIN problems ON games.problem_id = problems.problem_id @@ -263,6 +312,36 @@ func (q *Queries) ListGamesForPlayer(ctx context.Context, userID int32) ([]ListG return items, nil } +const listTestcasesByGameID = `-- name: ListTestcasesByGameID :many +SELECT testcase_id, problem_id, stdin, stdout FROM testcases +WHERE testcases.problem_id = (SELECT problem_id FROM games WHERE game_id = $1) +` + +func (q *Queries) ListTestcasesByGameID(ctx context.Context, gameID int32) ([]Testcase, error) { + rows, err := q.db.Query(ctx, listTestcasesByGameID, gameID) + if err != nil { + return nil, err + } + defer rows.Close() + var items []Testcase + for rows.Next() { + var i Testcase + if err := rows.Scan( + &i.TestcaseID, + &i.ProblemID, + &i.Stdin, + &i.Stdout, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + const listUsers = `-- name: ListUsers :many SELECT user_id, username, display_name, icon_path, is_admin, created_at FROM users ` diff --git a/backend/fixtures/dev.sql b/backend/fixtures/dev.sql index a468d01..e8b8716 100644 --- a/backend/fixtures/dev.sql +++ b/backend/fixtures/dev.sql @@ -47,3 +47,8 @@ VALUES (5, 2), (6, 1), (6, 2); + +INSERT INTO testcases +(problem_id, stdin, stdout) +VALUES + (4, '', '42'), diff --git a/backend/game/hub.go b/backend/game/hub.go index 70bf71f..bb82170 100644 --- a/backend/game/hub.go +++ b/backend/game/hub.go @@ -11,6 +11,7 @@ import ( "github.com/nsfisis/iosdc-japan-2024-albatross/backend/api" "github.com/nsfisis/iosdc-japan-2024-albatross/backend/db" + "github.com/nsfisis/iosdc-japan-2024-albatross/backend/taskqueue" ) type playerClientState int @@ -25,6 +26,7 @@ type gameHub struct { ctx context.Context game *game q *db.Queries + taskQueue *taskqueue.Queue players map[*playerClient]playerClientState registerPlayer chan *playerClient unregisterPlayer chan *playerClient @@ -32,13 +34,15 @@ type gameHub struct { watchers map[*watcherClient]bool registerWatcher chan *watcherClient unregisterWatcher chan *watcherClient + testcaseExecution chan string } -func newGameHub(ctx context.Context, game *game, q *db.Queries) *gameHub { +func newGameHub(ctx context.Context, game *game, q *db.Queries, taskQueue *taskqueue.Queue) *gameHub { return &gameHub{ ctx: ctx, game: game, q: q, + taskQueue: taskQueue, players: make(map[*playerClient]playerClientState), registerPlayer: make(chan *playerClient), unregisterPlayer: make(chan *playerClient), @@ -46,6 +50,7 @@ func newGameHub(ctx context.Context, game *game, q *db.Queries) *gameHub { watchers: make(map[*watcherClient]bool), registerWatcher: make(chan *watcherClient), unregisterWatcher: make(chan *watcherClient), + testcaseExecution: make(chan string), } } @@ -173,11 +178,25 @@ 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) } + case executionStatus := <-hub.testcaseExecution: + for player := range hub.players { + player.s2cMessages <- &playerMessageS2CExecResult{ + Type: playerMessageTypeS2CExecResult, + Data: playerMessageS2CExecResultPayload{ + Score: nil, + Status: api.GamePlayerMessageS2CExecResultPayloadStatus(executionStatus), + }, + } + } case <-ticker.C: if hub.game.state == gameStateStarting { if time.Now().After(*hub.game.startedAt) { @@ -258,14 +277,16 @@ func (hub *gameHub) closeWatcherClient(watcher *watcherClient) { } type GameHubs struct { - hubs map[int]*gameHub - q *db.Queries + hubs map[int]*gameHub + q *db.Queries + taskQueue *taskqueue.Queue } -func NewGameHubs(q *db.Queries) *GameHubs { +func NewGameHubs(q *db.Queries, taskQueue *taskqueue.Queue) *GameHubs { return &GameHubs{ - hubs: make(map[int]*gameHub), - q: q, + hubs: make(map[int]*gameHub), + q: q, + taskQueue: taskQueue, } } @@ -313,7 +334,7 @@ func (hubs *GameHubs) RestoreFromDB(ctx context.Context) error { startedAt: startedAt, problem: problem_, playerCount: len(playerRows), - }, hubs.q) + }, hubs.q, hubs.taskQueue) } return nil } @@ -335,3 +356,7 @@ func (hubs *GameHubs) StartGame(gameID int) error { } return hub.startGame() } + +func (hubs *GameHubs) C() chan string { + return hubs.hubs[4].testcaseExecution +} diff --git a/backend/go.mod b/backend/go.mod index fe678a0..bcb87fd 100644 --- a/backend/go.mod +++ b/backend/go.mod @@ -6,6 +6,7 @@ require ( github.com/getkin/kin-openapi v0.124.0 github.com/golang-jwt/jwt/v5 v5.2.1 github.com/gorilla/websocket v1.5.3 + github.com/hibiken/asynq v0.24.1 github.com/jackc/pgx/v5 v5.5.5 github.com/labstack/echo/v4 v4.12.0 github.com/oapi-codegen/echo-middleware v1.0.2 @@ -20,16 +21,18 @@ require ( filippo.io/edwards25519 v1.1.0 // indirect github.com/antlr4-go/antlr/v4 v4.13.0 // indirect github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect + github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/cubicdaiya/gonp v1.0.4 // indirect github.com/cznic/mathutil v0.0.0-20181122101859-297441e03548 // indirect github.com/davecgh/go-spew v1.1.1 // indirect + github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect github.com/dustin/go-humanize v1.0.1 // indirect github.com/fatih/structtag v1.2.0 // indirect github.com/go-openapi/jsonpointer v0.20.2 // indirect github.com/go-openapi/swag v0.22.8 // indirect github.com/go-sql-driver/mysql v1.8.1 // indirect github.com/golang-jwt/jwt v3.2.2+incompatible // indirect - github.com/golang/protobuf v1.5.3 // indirect + github.com/golang/protobuf v1.5.4 // indirect github.com/google/cel-go v0.20.1 // indirect github.com/google/uuid v1.6.0 // indirect github.com/gorilla/mux v1.8.1 // indirect @@ -53,8 +56,11 @@ require ( github.com/pingcap/failpoint v0.0.0-20220801062533-2eaa32854a6c // indirect github.com/pingcap/log v1.1.0 // indirect github.com/pingcap/tidb/pkg/parser v0.0.0-20231103154709-4f00ece106b1 // indirect + github.com/redis/go-redis/v9 v9.6.1 // indirect github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect github.com/riza-io/grpc-go v0.2.0 // indirect + github.com/robfig/cron/v3 v3.0.1 // indirect + github.com/spf13/cast v1.6.0 // indirect github.com/spf13/cobra v1.8.0 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/stoewer/go-strcase v1.2.0 // indirect @@ -69,14 +75,14 @@ require ( golang.org/x/mod v0.17.0 // indirect golang.org/x/net v0.25.0 // indirect golang.org/x/sync v0.7.0 // indirect - golang.org/x/sys v0.20.0 // indirect + golang.org/x/sys v0.23.0 // indirect golang.org/x/text v0.15.0 // indirect - golang.org/x/time v0.5.0 // indirect + golang.org/x/time v0.6.0 // indirect golang.org/x/tools v0.21.0 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20240123012728-ef4313101c80 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80 // indirect google.golang.org/grpc v1.62.1 // indirect - google.golang.org/protobuf v1.33.0 // indirect + google.golang.org/protobuf v1.34.2 // indirect gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/backend/go.sum b/backend/go.sum index b35e204..9d3e198 100644 --- a/backend/go.sum +++ b/backend/go.sum @@ -8,6 +8,15 @@ github.com/apapsch/go-jsonmerge/v2 v2.0.0 h1:axGnT1gRIfimI7gJifB699GoE/oq+F2MU7D github.com/apapsch/go-jsonmerge/v2 v2.0.0/go.mod h1:lvDnEdqiQrp0O42VQGgmlKpxL1AP2+08jFMw88y4klk= github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/bmatcuk/doublestar v1.1.1/go.mod h1:UD6OnuiIn0yFxxA2le/rnRU1G4RaI4UvFv1sNto9p6w= +github.com/bsm/ginkgo/v2 v2.7.0/go.mod h1:AiKlXPm7ItEHNc/2+OkrNG4E0ITzojb9/xWzvQ9XZ9w= +github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs= +github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c= +github.com/bsm/gomega v1.26.0/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0= +github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA= +github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0= +github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= +github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/cubicdaiya/gonp v1.0.4 h1:ky2uIAJh81WiLcGKBVD5R7KsM/36W6IqqTy6Bo6rGws= github.com/cubicdaiya/gonp v1.0.4/go.mod h1:iWGuP/7+JVTn02OWhRemVbMmG1DOUnmrGTYYACpOI0I= @@ -16,10 +25,14 @@ github.com/cznic/mathutil v0.0.0-20181122101859-297441e03548/go.mod h1:e6NPNENfs github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= +github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= github.com/fatih/structtag v1.2.0 h1:/OdNE99OxoI/PqaW/SuSK9uxxT3f/tcSZgon/ssNSx4= github.com/fatih/structtag v1.2.0/go.mod h1:mBJUNpUnHmRKrKlQQlmCrh5PuhftFbNv8Ys4/aAZl94= +github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= +github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= github.com/getkin/kin-openapi v0.124.0 h1:VSFNMB9C9rTKBnQ/fpyDU8ytMTr4dWI9QovSKj9kz/M= github.com/getkin/kin-openapi v0.124.0/go.mod h1:wb1aSZA/iWmorQP9KTAS/phLj/t17B5jT7+fS8ed9NM= github.com/go-openapi/jsonpointer v0.20.2 h1:mQc3nmndL8ZBzStEo3JYF8wzmeWffDH4VbXz58sAx6Q= @@ -35,15 +48,18 @@ github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzq github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk= github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= -github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= +github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= +github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/google/cel-go v0.20.1 h1:nDx9r8S3L4pE61eDdt8igGj8rf5kjYR3ILxWIpWNi84= github.com/google/cel-go v0.20.1/go.mod h1:kWcIzTsPX0zmQ+H3TirHstLLf9ep5QTsZBN9u4dOYLg= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26 h1:Xim43kblpZXfIBQsbuBVKCudVG457BR2GZFIz3uw3hQ= github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26/go.mod h1:dDKJzRmX4S37WGHujM7tX//fmj1uioxKzKxz3lo4HJo= +github.com/google/uuid v1.2.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= @@ -52,6 +68,8 @@ github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aN github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k= github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM= +github.com/hibiken/asynq v0.24.1 h1:+5iIEAyA9K/lcSPvx3qoPtsKJeKI5u9aOIvUmSsazEw= +github.com/hibiken/asynq v0.24.1/go.mod h1:u5qVeSbrnfT+vtG5Mq8ZPzQu/BmCKMHvTGb91uy9Tts= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= github.com/invopop/yaml v0.2.0 h1:7zky/qH+O0DwAyoobXUqvVBwgBFRxKoQ/3FjcVpjTMY= @@ -119,14 +137,22 @@ github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/redis/go-redis/v9 v9.0.3/go.mod h1:WqMKv5vnQbRuZstUwxQI195wHy+t4PuXDOjzMvcuQHk= +github.com/redis/go-redis/v9 v9.6.1 h1:HHDteefn6ZkTtY5fGUE8tj8uy85AHk6zP7CpzIAM0y4= +github.com/redis/go-redis/v9 v9.6.1/go.mod h1:0C0c6ycQsdpVNQpxb1njEQIqkx5UcsM8FJCQLgE9+RA= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= github.com/riza-io/grpc-go v0.2.0 h1:2HxQKFVE7VuYstcJ8zqpN84VnAoJ4dCL6YFhJewNcHQ= github.com/riza-io/grpc-go v0.2.0/go.mod h1:2bDvR9KkKC3KhtlSHfR3dAXjUMT86kg4UfWFyVGWqi8= +github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs= +github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro= github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM= +github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= +github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0= +github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0= github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= @@ -137,6 +163,7 @@ github.com/sqlc-dev/sqlc v1.26.0/go.mod h1:k2F3RWilLCup3D0XufrzZENCyXjtplALmHDmO github.com/stoewer/go-strcase v1.2.0 h1:Z2iHWqGXH00XYgqDmNgQbIBxf3wrNq0F3feEy0ainaU= github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= @@ -153,12 +180,14 @@ github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQ github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ= github.com/wasilibs/go-pgquery v0.0.0-20240319230125-b9b2e95c69a7 h1:sqqLVb63En4uTKFKBWSJ7c1aIFonhM1yn35/+KchOf4= github.com/wasilibs/go-pgquery v0.0.0-20240319230125-b9b2e95c69a7/go.mod h1:ZAUjWnxivykc22k0TKFZylOV0WlVQ9nWMExfGFIBuF4= +github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE= go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A= +go.uber.org/goleak v1.1.12/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= go.uber.org/goleak v1.2.0 h1:xqgm/S+aQvhWFTtR0XK3Jvg7z8kGV8P4X14IzwN3Eqk= go.uber.org/goleak v1.2.0/go.mod h1:XJYK+MuIchqpmGmUSAzotztawfKvYLUIgg7guXrwVUo= go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= @@ -169,37 +198,55 @@ go.uber.org/zap v1.19.0/go.mod h1:xg/QME4nWcxGxrpdeYfq7UvYrLh66cuVKdrbD1XF/NI= go.uber.org/zap v1.26.0 h1:sI7k6L95XOKS281NhVKOFCUNIvv9e0w4BF8N3u+tCRo= go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI= golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= golang.org/x/exp v0.0.0-20231108232855-2478ac86f678 h1:mchzmB1XO2pMaKFRqk/+MV3mgGG96aqaPXaMifQU47w= golang.org/x/exp v0.0.0-20231108232855-2478ac86f678/go.mod h1:zk2irFbV9DP96SEBUUAy67IdHUaZuSnrz1n472HUCLE= golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= +golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= -golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM= +golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= -golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk= -golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= +golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= +golang.org/x/time v0.6.0 h1:eTDhh4ZXt5Qf0augr54TN6suAUudPcawVZeIAPU7D4U= +golang.org/x/time v0.6.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20191108193012-7d206e10da11/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.21.0 h1:qc0xYgIbsSDt9EyWz05J5wfa7LOVW0YTLOXrqdLAWIw= golang.org/x/tools v0.21.0/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/genproto/googleapis/api v0.0.0-20240123012728-ef4313101c80 h1:Lj5rbfG876hIAYFjqiJnPHfhXbv+nzTWfm04Fg/XSVU= google.golang.org/genproto/googleapis/api v0.0.0-20240123012728-ef4313101c80/go.mod h1:4jWUdICTdgc3Ibxmr8nAJiiLHwQBY0UI0XZcEMaFKaA= google.golang.org/genproto/googleapis/rpc v0.0.0-20240123012728-ef4313101c80 h1:AjyfHzEPEFp/NpvfN5g+KDla3EMojjhRVZc1i7cj+oM= @@ -209,8 +256,8 @@ google.golang.org/grpc v1.62.1/go.mod h1:IWTG0VlJLCh1SkC58F7np9ka9mx/WNkjl4PGJai google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= -google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= -google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= +google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/backend/main.go b/backend/main.go index e2e4bbd..e3d0052 100644 --- a/backend/main.go +++ b/backend/main.go @@ -15,6 +15,7 @@ import ( "github.com/nsfisis/iosdc-japan-2024-albatross/backend/api" "github.com/nsfisis/iosdc-japan-2024-albatross/backend/db" "github.com/nsfisis/iosdc-japan-2024-albatross/backend/game" + "github.com/nsfisis/iosdc-japan-2024-albatross/backend/taskqueue" ) func connectDB(ctx context.Context, dsn string) (*pgxpool.Pool, error) { @@ -59,7 +60,9 @@ func main() { e.Use(middleware.Logger()) e.Use(middleware.Recover()) - gameHubs := game.NewGameHubs(queries) + taskQueue := taskqueue.NewQueue("task-db:6379") + + gameHubs := game.NewGameHubs(queries, taskQueue) err = gameHubs.RestoreFromDB(ctx) if err != nil { log.Fatalf("Error restoring game hubs from db %v", err) @@ -94,6 +97,11 @@ func main() { gameHubs.Run() + workerServer := taskqueue.NewWorkerServer("task-db:6379", queries, gameHubs.C()) + go func() { + workerServer.Run() + }() + if err := e.Start(":80"); err != http.ErrServerClosed { log.Fatal(err) } diff --git a/backend/query.sql b/backend/query.sql index 245d5cf..6395b9b 100644 --- a/backend/query.sql +++ b/backend/query.sql @@ -53,3 +53,16 @@ SET started_at = $6, problem_id = $7 WHERE game_id = $1; + +-- name: CreateSubmission :one +INSERT INTO submissions (game_id, user_id, code, code_size) +VALUES ($1, $2, $3, $4) +RETURNING submission_id; + +-- name: ListTestcasesByGameID :many +SELECT * FROM testcases +WHERE testcases.problem_id = (SELECT problem_id FROM games WHERE game_id = $1); + +-- name: CreateTestcaseExecution :exec +INSERT INTO testcase_executions (submission_id, testcase_id, status, stdout, stderr) +VALUES ($1, $2, $3, $4, $5); diff --git a/backend/schema.sql b/backend/schema.sql index 4a1d4b0..d0b6c40 100644 --- a/backend/schema.sql +++ b/backend/schema.sql @@ -52,3 +52,26 @@ CREATE TABLE testcases ( CONSTRAINT fk_problem_id FOREIGN KEY(problem_id) REFERENCES problems(problem_id) ); CREATE INDEX idx_testcases_problem_id ON testcases(problem_id); + +CREATE TABLE submissions ( + submission_id SERIAL PRIMARY KEY, + game_id INT NOT NULL, + user_id INT NOT NULL, + code TEXT NOT NULL, + code_size INT NOT NULL, + created_at TIMESTAMP NOT NULL DEFAULT NOW(), + CONSTRAINT fk_game_id FOREIGN KEY(game_id) REFERENCES games(game_id), + CONSTRAINT fk_user_id FOREIGN KEY(user_id) REFERENCES users(user_id) +); + +CREATE TABLE testcase_executions ( + testcase_execution_id SERIAL PRIMARY KEY, + submission_id INT NOT NULL, + testcase_id INT, + status VARCHAR(16) NOT NULL, + stdout TEXT NOT NULL, + stderr TEXT NOT NULL, + CONSTRAINT fk_submission_id FOREIGN KEY(submission_id) REFERENCES submissions(submission_id), + CONSTRAINT fk_testcase_id FOREIGN KEY(testcase_id) REFERENCES testcases(testcase_id) +); +CREATE INDEX idx_testcase_executions_submission_id ON testcase_executions(submission_id); diff --git a/backend/taskqueue/processor.go b/backend/taskqueue/processor.go new file mode 100644 index 0000000..e505c5a --- /dev/null +++ b/backend/taskqueue/processor.go @@ -0,0 +1,199 @@ +package taskqueue + +import ( + "bytes" + "context" + "encoding/json" + "fmt" + "net/http" + "strings" + + "github.com/hibiken/asynq" + + "github.com/nsfisis/iosdc-japan-2024-albatross/backend/db" +) + +type ExecProcessor struct { + q *db.Queries + c chan string +} + +func NewExecProcessor(q *db.Queries, c chan string) *ExecProcessor { + return &ExecProcessor{ + q: q, + c: c, + } +} + +func (p *ExecProcessor) ProcessTask(ctx context.Context, t *asynq.Task) error { + var payload TaskExecPlayload + if err := json.Unmarshal(t.Payload(), &payload); err != nil { + return fmt.Errorf("json.Unmarshal failed: %v: %w", err, asynq.SkipRetry) + } + + // TODO: upsert + // Create submission record. + submissionID, err := p.q.CreateSubmission(ctx, db.CreateSubmissionParams{ + GameID: int32(payload.GameID), + UserID: int32(payload.UserID), + Code: payload.Code, + CodeSize: int32(len(payload.Code)), // TODO: exclude whitespaces. + }) + if err != nil { + return fmt.Errorf("CreateSubmission failed: %v", err) + } + + { + type swiftcRequestData struct { + MaxDuration int `json:"max_duration_ms"` + Code string `json:"code"` + } + type swiftcResponseData struct { + Result string `json:"result"` + Stdout string `json:"stdout"` + Stderr string `json:"stderr"` + } + reqData := swiftcRequestData{ + MaxDuration: 5000, + Code: payload.Code, + } + reqJson, err := json.Marshal(reqData) + if err != nil { + return fmt.Errorf("json.Marshal failed: %v", err) + } + res, err := http.Post("http://worker:80/api/swiftc", "application/json", bytes.NewBuffer(reqJson)) + if err != nil { + return fmt.Errorf("http.Post failed: %v", err) + } + resData := swiftcResponseData{} + if err := json.NewDecoder(res.Body).Decode(&resData); err != nil { + return fmt.Errorf("json.Decode failed: %v", err) + } + if resData.Result != "success" { + err := p.q.CreateTestcaseExecution(ctx, db.CreateTestcaseExecutionParams{ + SubmissionID: submissionID, + TestcaseID: nil, + Status: "compile_error", + Stdout: resData.Stdout, + Stderr: resData.Stderr, + }) + if err != nil { + return fmt.Errorf("CreateTestcaseExecution failed: %v", err) + } + p.c <- "compile_error" + return fmt.Errorf("swiftc failed: %v", resData.Stderr) + } + } + { + type wasmcRequestData struct { + MaxDuration int `json:"max_duration_ms"` + Code string `json:"code"` + } + type wasmcResponseData struct { + Result string `json:"result"` + Stdout string `json:"stdout"` + Stderr string `json:"stderr"` + } + reqData := wasmcRequestData{ + MaxDuration: 5000, + Code: payload.Code, + } + reqJson, err := json.Marshal(reqData) + if err != nil { + return fmt.Errorf("json.Marshal failed: %v", err) + } + res, err := http.Post("http://worker:80/api/wasmc", "application/json", bytes.NewBuffer(reqJson)) + if err != nil { + return fmt.Errorf("http.Post failed: %v", err) + } + resData := wasmcResponseData{} + if err := json.NewDecoder(res.Body).Decode(&resData); err != nil { + return fmt.Errorf("json.Decode failed: %v", err) + } + if resData.Result != "success" { + err := p.q.CreateTestcaseExecution(ctx, db.CreateTestcaseExecutionParams{ + SubmissionID: submissionID, + TestcaseID: nil, + Status: "compile_error", + Stdout: resData.Stdout, + Stderr: resData.Stderr, + }) + if err != nil { + return fmt.Errorf("CreateTestcaseExecution failed: %v", err) + } + p.c <- "compile_error" + return fmt.Errorf("wasmc failed: %v", resData.Stderr) + } + } + + testcases, err := p.q.ListTestcasesByGameID(ctx, int32(payload.GameID)) + if err != nil { + return fmt.Errorf("ListTestcasesByGameID failed: %v", err) + } + + for _, testcase := range testcases { + type testrunRequestData struct { + MaxDuration int `json:"max_duration_ms"` + Code string `json:"code"` + Stdin string `json:"stdin"` + } + type testrunResponseData struct { + Result string `json:"result"` + Stdout string `json:"stdout"` + Stderr string `json:"stderr"` + } + reqData := testrunRequestData{ + MaxDuration: 5000, + Code: payload.Code, + Stdin: testcase.Stdin, + } + reqJson, err := json.Marshal(reqData) + if err != nil { + return fmt.Errorf("json.Marshal failed: %v", err) + } + res, err := http.Post("http://worker:80/api/testrun", "application/json", bytes.NewBuffer(reqJson)) + if err != nil { + return fmt.Errorf("http.Post failed: %v", err) + } + resData := testrunResponseData{} + if err := json.NewDecoder(res.Body).Decode(&resData); err != nil { + return fmt.Errorf("json.Decode failed: %v", err) + } + if resData.Result != "success" { + err := p.q.CreateTestcaseExecution(ctx, db.CreateTestcaseExecutionParams{ + SubmissionID: submissionID, + TestcaseID: &testcase.TestcaseID, + Status: resData.Result, + Stdout: resData.Stdout, + Stderr: resData.Stderr, + }) + if err != nil { + return fmt.Errorf("CreateTestcaseExecution failed: %v", err) + } + p.c <- resData.Result + return fmt.Errorf("testrun failed: %v", resData.Stderr) + } + if isTestcaseExecutionCorrect(testcase.Stdout, resData.Stdout) { + err := p.q.CreateTestcaseExecution(ctx, db.CreateTestcaseExecutionParams{ + SubmissionID: submissionID, + TestcaseID: &testcase.TestcaseID, + Status: "wrong_answer", + Stdout: resData.Stdout, + Stderr: resData.Stderr, + }) + if err != nil { + return fmt.Errorf("CreateTestcaseExecution failed: %v", err) + } + p.c <- "wrong_answer" + return fmt.Errorf("testrun failed: %v", resData.Stdout) + } + } + + return nil +} + +func isTestcaseExecutionCorrect(expectedStdout, actualStdout string) bool { + expectedStdout = strings.TrimSpace(expectedStdout) + actualStdout = strings.TrimSpace(actualStdout) + return actualStdout == expectedStdout +} diff --git a/backend/taskqueue/queue.go b/backend/taskqueue/queue.go new file mode 100644 index 0000000..53ec6d6 --- /dev/null +++ b/backend/taskqueue/queue.go @@ -0,0 +1,25 @@ +package taskqueue + +import ( + "github.com/hibiken/asynq" +) + +type Queue struct { + client *asynq.Client +} + +func NewQueue(redisAddr string) *Queue { + return &Queue{ + client: asynq.NewClient(asynq.RedisClientOpt{ + Addr: redisAddr, + }), + } +} + +func (q *Queue) Close() { + q.client.Close() +} + +func (q *Queue) Enqueue(task *asynq.Task, opts ...asynq.Option) (*asynq.TaskInfo, error) { + return q.client.Enqueue(task, opts...) +} diff --git a/backend/taskqueue/tasks.go b/backend/taskqueue/tasks.go new file mode 100644 index 0000000..cd67948 --- /dev/null +++ b/backend/taskqueue/tasks.go @@ -0,0 +1,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 +} diff --git a/backend/taskqueue/worker_server.go b/backend/taskqueue/worker_server.go new file mode 100644 index 0000000..485d6d3 --- /dev/null +++ b/backend/taskqueue/worker_server.go @@ -0,0 +1,33 @@ +package taskqueue + +import ( + "github.com/hibiken/asynq" + + "github.com/nsfisis/iosdc-japan-2024-albatross/backend/db" +) + +type WorkerServer struct { + server *asynq.Server + queries *db.Queries + c chan string +} + +func NewWorkerServer(redisAddr string, queries *db.Queries, c chan string) *WorkerServer { + return &WorkerServer{ + server: asynq.NewServer( + asynq.RedisClientOpt{ + Addr: redisAddr, + }, + asynq.Config{}, + ), + queries: queries, + c: c, + } +} + +func (s *WorkerServer) Run() error { + mux := asynq.NewServeMux() + mux.Handle(TaskTypeExec, NewExecProcessor(s.queries, s.c)) + + return s.server.Run(mux) +} diff --git a/compose.local.yaml b/compose.local.yaml index 6e5604f..883d640 100644 --- a/compose.local.yaml +++ b/compose.local.yaml @@ -7,6 +7,8 @@ services: depends_on: db: condition: service_healthy + task-db: + condition: service_healthy environment: ALBATROSS_DB_HOST: db ALBATROSS_DB_PORT: 5432 @@ -32,6 +34,17 @@ services: - db-data:/var/lib/postgresql/data restart: always + task-db: + image: redis:7.4.0 + expose: + - 6379 + healthcheck: + test: ["CMD-SHELL", "redis-cli ping"] + interval: 10s + timeout: 5s + retries: 5 + restart: always + worker: build: context: ./worker diff --git a/frontend/app/.server/api/schema.d.ts b/frontend/app/.server/api/schema.d.ts index 62badcf..6981dea 100644 --- a/frontend/app/.server/api/schema.d.ts +++ b/frontend/app/.server/api/schema.d.ts @@ -150,7 +150,7 @@ export interface components { * @example success * @enum {string} */ - status: "success"; + status: "success" | "failure" | "timeout" | "internal_error" | "compile_error" | "wrong_answer"; /** @example 100 */ score: number | null; }; diff --git a/frontend/app/components/GolfPlayApp.client.tsx b/frontend/app/components/GolfPlayApp.client.tsx index 80e7182..911fae0 100644 --- a/frontend/app/components/GolfPlayApp.client.tsx +++ b/frontend/app/components/GolfPlayApp.client.tsx @@ -73,6 +73,8 @@ export default function GolfPlayApp({ const [currentScore, setCurrentScore] = useState<number | null>(null); + const [lastExecStatus, setLastExecStatus] = useState<string | null>(null); + const onCodeChange = useDebouncedCallback((code: string) => { console.log("player:c2s:code"); sendJsonMessage({ @@ -121,13 +123,14 @@ export default function GolfPlayApp({ setGameState("starting"); } } else if (lastJsonMessage.type === "player:s2c:execresult") { - const { score } = lastJsonMessage.data; + const { status, score } = lastJsonMessage.data; if ( score !== null && (currentScore === null || score < currentScore) ) { setCurrentScore(score); } + setLastExecStatus(status); } } else { setGameState("waiting"); @@ -150,6 +153,7 @@ export default function GolfPlayApp({ onCodeChange={onCodeChange} onCodeSubmit={onCodeSubmit} currentScore={currentScore} + lastExecStatus={lastExecStatus} /> ); } else if (gameState === "finished") { diff --git a/frontend/app/components/GolfPlayApps/GolfPlayAppGaming.tsx b/frontend/app/components/GolfPlayApps/GolfPlayAppGaming.tsx index 9fddb01..1a08b98 100644 --- a/frontend/app/components/GolfPlayApps/GolfPlayAppGaming.tsx +++ b/frontend/app/components/GolfPlayApps/GolfPlayAppGaming.tsx @@ -5,6 +5,7 @@ type Props = { onCodeChange: (code: string) => void; onCodeSubmit: (code: string) => void; currentScore: number | null; + lastExecStatus: string | null; }; export default function GolfPlayAppGaming({ @@ -12,6 +13,7 @@ export default function GolfPlayAppGaming({ onCodeChange, onCodeSubmit, currentScore, + lastExecStatus, }: Props) { const textareaRef = useRef<HTMLTextAreaElement>(null); @@ -36,7 +38,8 @@ export default function GolfPlayAppGaming({ <div className="mb-4 mt-auto"> <div className="mb-2"> <div className="font-semibold text-green-500"> - Score: {currentScore == null ? "-" : `${currentScore}`} + Score: {currentScore == null ? "-" : `${currentScore}`} ( + {lastExecStatus}) </div> </div> <button diff --git a/openapi.yaml b/openapi.yaml index 2e18728..0e46fca 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -300,6 +300,11 @@ components: example: "success" enum: - success + - failure + - timeout + - internal_error + - compile_error + - wrong_answer score: type: integer nullable: true |
