Implement runners execute route

Co-authored-by: Tobias Kantusch <tobias.kantusch@student.hpi.uni-potsdam.de>
This commit is contained in:
Konrad Hanff
2021-04-30 16:21:44 +02:00
parent c571d4635d
commit 6a00ea3165
7 changed files with 177 additions and 362 deletions

View File

@ -1,6 +1,7 @@
package runner
import (
"context"
"encoding/json"
"sync"
)
@ -12,6 +13,9 @@ const (
StatusRunning Status = "running"
StatusTimeout Status = "timeout"
StatusFinished Status = "finished"
// runnerContextKey is the key used to store runners in context.Context
runnerContextKey = "runner"
)
type Runner interface {
@ -69,3 +73,12 @@ func (r *ExerciseRunner) Status() Status {
func (r *ExerciseRunner) Id() string {
return r.id
}
func NewContext(ctx context.Context, runner *Runner) context.Context {
return context.WithValue(ctx, runnerContextKey, runner)
}
func FromContext(ctx context.Context) (*Runner, bool) {
runner, ok := ctx.Value(runnerContextKey).(*Runner)
return runner, ok
}