Skip to content

Commit

Permalink
fix: some struct changes & better logging
Browse files Browse the repository at this point in the history
  • Loading branch information
angristan committed Jul 6, 2021
1 parent 2c2e403 commit f6dce57
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
17 changes: 12 additions & 5 deletions job.go
Expand Up @@ -14,6 +14,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)
return
}
Expand All @@ -31,9 +32,10 @@ func (job benchJob) run(ctx context.Context, WarmVMs <-chan runningFirecracker)
var reqJSON []byte

reqJSON, err = json.Marshal(agentRunReq{
ID: job.ID,
Variant: job.Variant,
Code: job.Code,
ID: job.ID,
Language: job.Language,
Code: job.Code,
Variant: "TODO",
})
if err != nil {
log.WithError(err).Error("Failed to marshal JSON request")
Expand All @@ -43,6 +45,7 @@ func (job benchJob) run(ctx context.Context, WarmVMs <-chan runningFirecracker)

err = q.setjobRunning(ctx, job)
if err != nil {
log.WithError(err).Error("Could not set job running")
q.setjobFailed(ctx, job)
return
}
Expand All @@ -51,7 +54,7 @@ func (job benchJob) run(ctx context.Context, WarmVMs <-chan runningFirecracker)
var agentRes agentExecRes

// FIXME
httpRes, err = http.Post("http://"+vm.ip.String()+":8080/run/python", "application/json", bytes.NewBuffer(reqJSON))
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)
Expand All @@ -60,7 +63,11 @@ func (job benchJob) run(ctx context.Context, WarmVMs <-chan runningFirecracker)
json.NewDecoder(httpRes.Body).Decode(&agentRes)
log.WithField("result", agentRes).Info("Job execution finished")
if httpRes.StatusCode != 200 {
log.WithField("res", agentRes).Error("Failed to compile and run code")
log.WithFields(log.Fields{
"httpRes": httpRes,
"agentRes": agentRes,
"reqJSON": string(reqJSON),
}).Error("Failed to compile and run code")
q.setjobFailed(ctx, job)
return
}
Expand Down
13 changes: 7 additions & 6 deletions main.go
Expand Up @@ -18,9 +18,9 @@ import (
)

type benchJob struct {
ID string `json:"id"`
Variant string `json:"variant"`
Code string `json:"code"`
ID string `json:"id"`
Language string `json:"language"`
Code string `json:"code"`
}

type agentExecReq struct {
Expand All @@ -29,9 +29,10 @@ type agentExecReq struct {
}

type agentRunReq struct {
ID string `json:"id"`
Variant string `json:"variant"`
Code string `json:"code"`
ID string `json:"id"`
Language string `json:"language"`
Code string `json:"code"`
Variant string `json:"variant"`
}

type agentExecRes struct {
Expand Down

0 comments on commit f6dce57

Please sign in to comment.