Implement runners execute route
Co-authored-by: Tobias Kantusch <tobias.kantusch@student.hpi.uni-potsdam.de>
This commit is contained in:
@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user