aboutsummaryrefslogtreecommitdiffhomepage
path: root/backend
diff options
context:
space:
mode:
Diffstat (limited to 'backend')
-rw-r--r--backend/api/generated.go58
-rw-r--r--backend/game/hub.go16
-rw-r--r--backend/main.go2
-rw-r--r--backend/taskqueue/processor.go8
-rw-r--r--backend/taskqueue/worker_server.go7
5 files changed, 61 insertions, 30 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",
- "mqILa5WPOHxNCY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f368ZaQwxCuPTas04PBc46h39H47xNqZ22X6mv8Hgn4hsbVLs+T5J116IOw3jWHjWpB4ydkG4fXW7T",
+ "4NOKyIDIAAfldLH/kM1rOyii6E7FK1C1HTS2TziWZ1aTe+za5vRnCeKUQ8/f+YoFv3Jo85REnM3MJYAj",
+ "0icJXoLs3/EV692ly1ZROcNxQtz4LjCV9eafc04BmyPyTLaUl9FFW0T10qYXGsrReJZWtpQ0zgUr3M3Y",
+ "anWELbg5cLB5RVd0jpXgUgblL4xgDfPgavIOhegehLSn44PesDfQ6HkKDKcEjdFFb9AbIHvxYlLUX+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/game/hub.go b/backend/game/hub.go
index 0b12ce9..bb82170 100644
--- a/backend/game/hub.go
+++ b/backend/game/hub.go
@@ -34,6 +34,7 @@ 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, taskQueue *taskqueue.Queue) *gameHub {
@@ -49,6 +50,7 @@ func newGameHub(ctx context.Context, game *game, q *db.Queries, taskQueue *taskq
watchers: make(map[*watcherClient]bool),
registerWatcher: make(chan *watcherClient),
unregisterWatcher: make(chan *watcherClient),
+ testcaseExecution: make(chan string),
}
}
@@ -185,6 +187,16 @@ func (hub *gameHub) run() {
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) {
@@ -344,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/main.go b/backend/main.go
index 7cfbe2f..e3d0052 100644
--- a/backend/main.go
+++ b/backend/main.go
@@ -61,7 +61,6 @@ func main() {
e.Use(middleware.Recover())
taskQueue := taskqueue.NewQueue("task-db:6379")
- workerServer := taskqueue.NewWorkerServer("task-db:6379", queries)
gameHubs := game.NewGameHubs(queries, taskQueue)
err = gameHubs.RestoreFromDB(ctx)
@@ -98,6 +97,7 @@ func main() {
gameHubs.Run()
+ workerServer := taskqueue.NewWorkerServer("task-db:6379", queries, gameHubs.C())
go func() {
workerServer.Run()
}()
diff --git a/backend/taskqueue/processor.go b/backend/taskqueue/processor.go
index 1105da5..e505c5a 100644
--- a/backend/taskqueue/processor.go
+++ b/backend/taskqueue/processor.go
@@ -15,11 +15,13 @@ import (
type ExecProcessor struct {
q *db.Queries
+ c chan string
}
-func NewExecProcessor(q *db.Queries) *ExecProcessor {
+func NewExecProcessor(q *db.Queries, c chan string) *ExecProcessor {
return &ExecProcessor{
q: q,
+ c: c,
}
}
@@ -78,6 +80,7 @@ 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"
return fmt.Errorf("swiftc failed: %v", resData.Stderr)
}
}
@@ -118,6 +121,7 @@ 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"
return fmt.Errorf("wasmc failed: %v", resData.Stderr)
}
}
@@ -166,6 +170,7 @@ 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
return fmt.Errorf("testrun failed: %v", resData.Stderr)
}
if isTestcaseExecutionCorrect(testcase.Stdout, resData.Stdout) {
@@ -179,6 +184,7 @@ 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"
return fmt.Errorf("testrun failed: %v", resData.Stdout)
}
}
diff --git a/backend/taskqueue/worker_server.go b/backend/taskqueue/worker_server.go
index 09d9761..485d6d3 100644
--- a/backend/taskqueue/worker_server.go
+++ b/backend/taskqueue/worker_server.go
@@ -9,9 +9,10 @@ import (
type WorkerServer struct {
server *asynq.Server
queries *db.Queries
+ c chan string
}
-func NewWorkerServer(redisAddr string, queries *db.Queries) *WorkerServer {
+func NewWorkerServer(redisAddr string, queries *db.Queries, c chan string) *WorkerServer {
return &WorkerServer{
server: asynq.NewServer(
asynq.RedisClientOpt{
@@ -19,12 +20,14 @@ func NewWorkerServer(redisAddr string, queries *db.Queries) *WorkerServer {
},
asynq.Config{},
),
+ queries: queries,
+ c: c,
}
}
func (s *WorkerServer) Run() error {
mux := asynq.NewServeMux()
- mux.Handle(TaskTypeExec, NewExecProcessor(s.queries))
+ mux.Handle(TaskTypeExec, NewExecProcessor(s.queries, s.c))
return s.server.Run(mux)
}