-
Notifications
You must be signed in to change notification settings - Fork 8
Add the job start time to build info file #47
Conversation
apostergiou
commented
Apr 20, 2018
•
edited
Loading
edited
- Rename buildResult to buildInfo
- Add start time to build info
- work: Write build info file before container start
- web view index: Sort jobs by started time on index page web view: Sort jobs by started time on index page #42
- web view show: get job start time from the build info file
a3e98b5
to
3ffba9a
Compare
3ffba9a
to
f85d068
Compare
cmd/mistryd/mistryd_test.go
Outdated
@@ -151,7 +151,7 @@ func TestPruneZombieBuilds(t *testing.T) { | |||
} | |||
} | |||
|
|||
func readOut(br *types.BuildResult, path string) (string, error) { | |||
func readOut(br *types.BuildInfo, path string) (string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
br
-> bi
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
cmd/mistryd/worker.go
Outdated
return | ||
} | ||
|
||
infoFile.Seek(0, 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should always check & handle errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch, fixed
cmd/mistryd/worker.go
Outdated
|
||
err = j.BuildImage(ctx, s.cfg.UID, client, out) | ||
if err != nil { | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noticed that we do not set any errors here. We should fix this at this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -118,6 +118,8 @@ func NewJob(project string, params types.Params, group string, cfg *Config) (*Jo | |||
j.Image = ImgCntPrefix + j.ID | |||
j.Container = ImgCntPrefix + j.ID | |||
|
|||
j.StartedAt = time.Now() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
StartedAt
is not needed in Job{}
. It should only exist in BuildInfo{}
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, we only need this for the index sort. Nevertheless, I say we take care of this in another PR as it affects the server and the job JSON encoding. Opened a new issue to track it #49.
cmd/mistryd/server.go
Outdated
if err != nil { | ||
s.Log.Print(err) | ||
w.WriteHeader(http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
jDir, err := ioutil.ReadDir(jPath) | ||
buildLog, err = ioutil.ReadFile(buildLogPath) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[minor] IMHO log
is a better name
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed
cmd/mistryd/server.go
Outdated
w.WriteHeader(http.StatusInternalServerError) | ||
return | ||
} | ||
err = json.Unmarshal(biBlob, &bi) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if err is not nil?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, handled.
cmd/mistryd/server.go
Outdated
w.WriteHeader(http.StatusInternalServerError) | ||
return | ||
} | ||
err = json.Unmarshal(biBlob, &bi) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
cmd/mistryd/server.go
Outdated
jobs = append(jobs, Job{ | ||
ID: j.Name(), | ||
Project: p.Name(), | ||
StartedAt: j.ModTime(), | ||
Output: filepath.Join(pendingPath, j.Name(), BuildLogFname), | ||
StartedAt: bi.StartedAt, | ||
State: "pending"}) | ||
} | ||
|
||
for _, j := range readyJobs { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The body of this loop is the exact same with the one some lines above. Can we somehow get rid of this repetition?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Introduced a GetJobs
function and extracted the repetitive code to a buildInfo function.
@@ -1,12 +1,6 @@ | |||
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use BuildResult (as opposed to buildResult) and BuildInfo in the commit message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
f85d068
to
9175c2b
Compare
cmd/mistryd/job.go
Outdated
@@ -275,3 +278,51 @@ func GetState(path, project, id string) (string, error) { | |||
} | |||
return "", fmt.Errorf("job with id=%s not found error", id) | |||
} | |||
|
|||
func GetJobs(path string) ([]Job, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add documentation. Also, this should be unexported.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This belongs to the server.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
cmd/mistryd/job.go
Outdated
ID: j.Name(), | ||
Project: p.Name(), | ||
StartedAt: bi.StartedAt, | ||
State: "ready"}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The repetition here still remains. You do the exact same things for pendingJobs
and readyJobs
. We could DRY this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
6743d79
to
0c6a214
Compare
pkg/types/build_info.go
Outdated
@@ -36,3 +41,16 @@ type ErrImageBuild struct { | |||
func (e ErrImageBuild) Error() string { | |||
return fmt.Sprintf("could not build docker image '%s': %s", e.Image, e.Err) | |||
} | |||
|
|||
func GetBuildInfo(path string) (BuildInfo, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function doesn't belong in this package. I'd say to not make this a function at all, since it's only used in a single place inside the server.
(Since it was exported it should also have documentation).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, since we refactored the getJob to work as a closure, we can delete the extra function.
jobInfo.innerHTML += "ExitCode: ".big() + jobJSON["ExitCode"] + "<br>"; | ||
jobInfo.innerHTML += "Transport method: ".big() + jobJSON["TransportMethod"] + "<br>"; | ||
} | ||
jobInfo.innerHTML += "Started At: ".big() + jobJSON["StartedAt"] + "<br>"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we parse this and return a more human representation of the date? Eg. DD-MM-YYYY 12:34:123 +300
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
for _, p := range projects { | ||
pendingPath := filepath.Join(s.cfg.BuildPath, p.Name(), "pending") | ||
_, err := os.Stat(pendingPath) | ||
pendingExists := !os.IsNotExist(err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if err
is not nil and not a "not exist" error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
cmd/mistryd/server.go
Outdated
pendingExists := !os.IsNotExist(err) | ||
readyPath := filepath.Join(s.cfg.BuildPath, p.Name(), "ready") | ||
_, err = os.Stat(readyPath) | ||
readyExists := !os.IsNotExist(err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
Log: template.HTML(strings.Replace(string(log), "\n", "<br />", -1)), | ||
ID: id, | ||
Project: project, | ||
State: state, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we need StartedAt
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, the view parses the output field. In addition, since we want to remove the StartedAt
from the job, I suggest we leave this be.
return nil, fmt.Errorf("cannot find job %s; %s", j.Name(), err) | ||
} | ||
jobs = append(jobs, job) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could get rid of the 2nd loop (it is identical to 1st one), if you concatenate the two slices:
for _, j := range append(pendingJobs, readyJobs...)
// ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These loops are not identical.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah true.
bbbfef6
to
bf34ea9
Compare
80e4bcf
to
dd45d61
Compare