Add basic websocket structure and request upgrader

This commit is contained in:
Maximilian Paß
2021-05-07 14:10:12 +02:00
parent e07e8216f2
commit 465577fea6
4 changed files with 81 additions and 10 deletions

View File

@@ -5,10 +5,14 @@ import (
"encoding/json"
"github.com/google/uuid"
"gitlab.hpi.de/codeocean/codemoon/poseidon/api/dto"
"gitlab.hpi.de/codeocean/codemoon/poseidon/logging"
"gitlab.hpi.de/codeocean/codemoon/poseidon/store"
"sync"
"time"
)
var log = logging.GetLogger("runner")
// Status is the type for the status of a Runner.
type Status string
@@ -46,6 +50,10 @@ type Runner interface {
// DeleteExecution deletes the execution of the runner with the specified id.
DeleteExecution(ExecutionId)
// Execute runs one of the runners Executions by it's id
// ok will be false if the runner has no execution with the provided id
Execute(ExecutionId) (err error, ok bool)
}
// ExerciseRunner is an abstraction to communicate with Nomad allocations.
@@ -120,6 +128,19 @@ func (r *ExerciseRunner) DeleteExecution(id ExecutionId) {
delete(r.executions, id)
}
func (r *ExerciseRunner) Execute(id ExecutionId) (err error, ok bool) {
execution, ok := r.Execution(id)
if !ok {
return
}
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(execution.TimeLimit)*time.Second)
defer cancel()
log.WithField("Context", ctx).Printf("ToDo: Running execution")
// ToDo: Implement command execution
// r.nomadApiClient.ExecuteCommand(r.id, ctx, )
return
}
// NewContext creates a context containing a runner.
func NewContext(ctx context.Context, runner Runner) context.Context {
return context.WithValue(ctx, runnerContextKey, runner)