Skip to content

Commit 4dcbb44

Browse files
committed
feat: transmit errors in job status
1 parent f6dce57 commit 4dcbb44

File tree

3 files changed

+23
-15
lines changed

3 files changed

+23
-15
lines changed

job.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ func (job benchJob) run(ctx context.Context, WarmVMs <-chan runningFirecracker)
1515
err := q.setjobReceived(ctx, job)
1616
if err != nil {
1717
log.WithError(err).Error("Could not set job received")
18-
q.setjobFailed(ctx, job)
18+
q.setjobFailed(ctx, job, agentExecRes{Error: err.Error()})
1919
return
2020
}
2121

@@ -39,14 +39,14 @@ func (job benchJob) run(ctx context.Context, WarmVMs <-chan runningFirecracker)
3939
})
4040
if err != nil {
4141
log.WithError(err).Error("Failed to marshal JSON request")
42-
q.setjobFailed(ctx, job)
42+
q.setjobFailed(ctx, job, agentExecRes{Error: err.Error()})
4343
return
4444
}
4545

4646
err = q.setjobRunning(ctx, job)
4747
if err != nil {
4848
log.WithError(err).Error("Could not set job running")
49-
q.setjobFailed(ctx, job)
49+
q.setjobFailed(ctx, job, agentExecRes{Error: err.Error()})
5050
return
5151
}
5252

@@ -57,7 +57,7 @@ func (job benchJob) run(ctx context.Context, WarmVMs <-chan runningFirecracker)
5757
httpRes, err = http.Post("http://"+vm.ip.String()+":8080/run", "application/json", bytes.NewBuffer(reqJSON))
5858
if err != nil {
5959
log.WithError(err).Error("Failed to request execution to agent")
60-
q.setjobFailed(ctx, job)
60+
q.setjobFailed(ctx, job, agentExecRes{Error: err.Error()})
6161
return
6262
}
6363
json.NewDecoder(httpRes.Body).Decode(&agentRes)
@@ -68,13 +68,13 @@ func (job benchJob) run(ctx context.Context, WarmVMs <-chan runningFirecracker)
6868
"agentRes": agentRes,
6969
"reqJSON": string(reqJSON),
7070
}).Error("Failed to compile and run code")
71-
q.setjobFailed(ctx, job)
71+
q.setjobFailed(ctx, job, agentRes)
7272
return
7373
}
7474

7575
err = q.setjobResult(ctx, job, agentRes)
7676
if err != nil {
77-
q.setjobFailed(ctx, job)
77+
q.setjobFailed(ctx, job, agentExecRes{Error: err.Error()})
7878
}
7979

8080
}

job_queue_rabbitmq.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ type jobQueue struct {
1818
type jobStatus struct {
1919
ID string `json:"id"`
2020
Status string `json:"status"`
21+
Message string `json:"message"`
22+
Error string `json:"error"`
2123
StdErr string `json:"stderr"`
2224
StdOut string `json:"stdout"`
2325
ExecDuration int `json:"exec_duration"`
@@ -101,13 +103,15 @@ func (q jobQueue) getQueueForJob(ctx context.Context) error {
101103
)
102104
}
103105

104-
func (q jobQueue) setjobStatus(ctx context.Context, job benchJob, status string) error {
106+
func (q jobQueue) setjobStatus(ctx context.Context, job benchJob, status string, res agentExecRes) error {
105107
log.WithField("status", status).Info("Set job status")
106108
jobStatus := &jobStatus{
107-
ID: job.ID,
108-
Status: status,
109-
StdErr: "",
110-
StdOut: "",
109+
ID: job.ID,
110+
Status: status,
111+
Message: res.Message,
112+
Error: res.Error,
113+
StdErr: "",
114+
StdOut: "",
111115
}
112116
b, err := json.Marshal(jobStatus)
113117
if err != nil {
@@ -126,20 +130,22 @@ func (q jobQueue) setjobStatus(ctx context.Context, job benchJob, status string)
126130
}
127131

128132
func (q jobQueue) setjobReceived(ctx context.Context, job benchJob) error {
129-
return q.setjobStatus(ctx, job, "received")
133+
return q.setjobStatus(ctx, job, "received", agentExecRes{})
130134
}
131135

132136
func (q jobQueue) setjobRunning(ctx context.Context, job benchJob) error {
133-
return q.setjobStatus(ctx, job, "running")
137+
return q.setjobStatus(ctx, job, "running", agentExecRes{})
134138
}
135139

136-
func (q jobQueue) setjobFailed(ctx context.Context, job benchJob) error {
137-
return q.setjobStatus(ctx, job, "failed")
140+
func (q jobQueue) setjobFailed(ctx context.Context, job benchJob, res agentExecRes) error {
141+
return q.setjobStatus(ctx, job, "failed", res)
138142
}
139143
func (q jobQueue) setjobResult(ctx context.Context, job benchJob, res agentExecRes) error {
140144
jobStatus := &jobStatus{
141145
ID: job.ID,
142146
Status: "done",
147+
Message: res.Message,
148+
Error: res.Error,
143149
StdErr: res.StdErr,
144150
StdOut: res.StdOut,
145151
ExecDuration: res.ExecDuration,

main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ type agentRunReq struct {
3636
}
3737

3838
type agentExecRes struct {
39+
Message string `json:"message"`
40+
Error string `json:"error"`
3941
StdErr string `json:"stderr"`
4042
StdOut string `json:"stdout"`
4143
ExecDuration int `json:"exec_duration"`

0 commit comments

Comments
 (0)