diff --git a/job.go b/job.go index a7278aa..a21a2c3 100644 --- a/job.go +++ b/job.go @@ -15,7 +15,7 @@ func (job benchJob) run(ctx context.Context, WarmVMs <-chan runningFirecracker) err := q.setjobReceived(ctx, job) if err != nil { log.WithError(err).Error("Could not set job received") - q.setjobFailed(ctx, job) + q.setjobFailed(ctx, job, agentExecRes{Error: err.Error()}) return } @@ -39,14 +39,14 @@ func (job benchJob) run(ctx context.Context, WarmVMs <-chan runningFirecracker) }) if err != nil { log.WithError(err).Error("Failed to marshal JSON request") - q.setjobFailed(ctx, job) + q.setjobFailed(ctx, job, agentExecRes{Error: err.Error()}) return } err = q.setjobRunning(ctx, job) if err != nil { log.WithError(err).Error("Could not set job running") - q.setjobFailed(ctx, job) + q.setjobFailed(ctx, job, agentExecRes{Error: err.Error()}) return } @@ -57,7 +57,7 @@ func (job benchJob) run(ctx context.Context, WarmVMs <-chan runningFirecracker) httpRes, err = http.Post("http://"+vm.ip.String()+":8080/run", "application/json", bytes.NewBuffer(reqJSON)) if err != nil { log.WithError(err).Error("Failed to request execution to agent") - q.setjobFailed(ctx, job) + q.setjobFailed(ctx, job, agentExecRes{Error: err.Error()}) return } json.NewDecoder(httpRes.Body).Decode(&agentRes) @@ -68,13 +68,13 @@ func (job benchJob) run(ctx context.Context, WarmVMs <-chan runningFirecracker) "agentRes": agentRes, "reqJSON": string(reqJSON), }).Error("Failed to compile and run code") - q.setjobFailed(ctx, job) + q.setjobFailed(ctx, job, agentRes) return } err = q.setjobResult(ctx, job, agentRes) if err != nil { - q.setjobFailed(ctx, job) + q.setjobFailed(ctx, job, agentExecRes{Error: err.Error()}) } } diff --git a/job_queue_rabbitmq.go b/job_queue_rabbitmq.go index ed21dc9..717fa83 100644 --- a/job_queue_rabbitmq.go +++ b/job_queue_rabbitmq.go @@ -18,6 +18,8 @@ type jobQueue struct { type jobStatus struct { ID string `json:"id"` Status string `json:"status"` + Message string `json:"message"` + Error string `json:"error"` StdErr string `json:"stderr"` StdOut string `json:"stdout"` ExecDuration int `json:"exec_duration"` @@ -101,13 +103,15 @@ func (q jobQueue) getQueueForJob(ctx context.Context) error { ) } -func (q jobQueue) setjobStatus(ctx context.Context, job benchJob, status string) error { +func (q jobQueue) setjobStatus(ctx context.Context, job benchJob, status string, res agentExecRes) error { log.WithField("status", status).Info("Set job status") jobStatus := &jobStatus{ - ID: job.ID, - Status: status, - StdErr: "", - StdOut: "", + ID: job.ID, + Status: status, + Message: res.Message, + Error: res.Error, + StdErr: "", + StdOut: "", } b, err := json.Marshal(jobStatus) if err != nil { @@ -126,20 +130,22 @@ func (q jobQueue) setjobStatus(ctx context.Context, job benchJob, status string) } func (q jobQueue) setjobReceived(ctx context.Context, job benchJob) error { - return q.setjobStatus(ctx, job, "received") + return q.setjobStatus(ctx, job, "received", agentExecRes{}) } func (q jobQueue) setjobRunning(ctx context.Context, job benchJob) error { - return q.setjobStatus(ctx, job, "running") + return q.setjobStatus(ctx, job, "running", agentExecRes{}) } -func (q jobQueue) setjobFailed(ctx context.Context, job benchJob) error { - return q.setjobStatus(ctx, job, "failed") +func (q jobQueue) setjobFailed(ctx context.Context, job benchJob, res agentExecRes) error { + return q.setjobStatus(ctx, job, "failed", res) } func (q jobQueue) setjobResult(ctx context.Context, job benchJob, res agentExecRes) error { jobStatus := &jobStatus{ ID: job.ID, Status: "done", + Message: res.Message, + Error: res.Error, StdErr: res.StdErr, StdOut: res.StdOut, ExecDuration: res.ExecDuration, diff --git a/main.go b/main.go index 49630d5..ef535f9 100644 --- a/main.go +++ b/main.go @@ -36,6 +36,8 @@ type agentRunReq struct { } type agentExecRes struct { + Message string `json:"message"` + Error string `json:"error"` StdErr string `json:"stderr"` StdOut string `json:"stdout"` ExecDuration int `json:"exec_duration"`