diff --git a/internal/api/runners.go b/internal/api/runners.go index 7579db2..a4c0095 100644 --- a/internal/api/runners.go +++ b/internal/api/runners.go @@ -133,6 +133,7 @@ func (r *RunnerController) updateFileSystem(writer http.ResponseWriter, request func (r *RunnerController) fileContent(writer http.ResponseWriter, request *http.Request) { targetRunner, _ := runner.FromContext(request.Context()) + monitoring.AddRunnerMonitoringData(request, targetRunner.ID(), targetRunner.Environment()) path := request.URL.Query().Get(PathKey) privilegedExecution, err := strconv.ParseBool(request.URL.Query().Get(PrivilegedExecutionKey)) if err != nil { diff --git a/internal/nomad/api_querier.go b/internal/nomad/api_querier.go index 0d8061d..1af77c9 100644 --- a/internal/nomad/api_querier.go +++ b/internal/nomad/api_querier.go @@ -100,16 +100,18 @@ func (nc *nomadAPIClient) Execute(runnerID string, return 1, fmt.Errorf("error retrieving allocation info: %w", err) } exitCode, err := nc.client.Allocations().Exec(ctx, allocation, TaskName, tty, command, stdin, stdout, stderr, nil, nil) - if err != nil { - rootCause := errors.Unwrap(err) - if rootCause != nil && websocket.IsCloseError(rootCause, websocket.CloseNormalClosure) { - log.WithError(err).Info("The exit code could not be received.") - return 0, nil - } else { - return 1, fmt.Errorf("error executing command in allocation: %w", err) - } + switch { + case err == nil: + return exitCode, nil + case websocket.IsCloseError(errors.Unwrap(err), websocket.CloseNormalClosure): + log.WithField("runnerID", runnerID).WithError(err).Info("The exit code could not be received.") + return 0, nil + case errors.Is(err, context.Canceled): + log.WithField("runnerID", runnerID).Infof("Execution canceled by context") + return 0, nil + default: + return 1, fmt.Errorf("error executing command in allocation: %w", err) } - return exitCode, nil } func (nc *nomadAPIClient) listJobs(prefix string) ([]*nomadApi.JobListStub, error) {