Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

Add the job start time to build info file #47

Merged
merged 8 commits into from
Apr 25, 2018
Merged

Conversation

apostergiou
Copy link
Contributor

@apostergiou apostergiou commented Apr 20, 2018

  • 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

@apostergiou apostergiou changed the title [wip] Fix dir modtime Fix dir modtime Apr 23, 2018
@apostergiou apostergiou changed the title Fix dir modtime Add the job start time to build info file Apr 23, 2018
@apostergiou apostergiou requested review from agis and dtheodor April 23, 2018 07:03
@apostergiou apostergiou self-assigned this Apr 23, 2018
@apostergiou apostergiou added this to the 1.0 milestone Apr 23, 2018
@@ -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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

br -> bi

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

return
}

infoFile.Seek(0, 0)
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, fixed


err = j.BuildImage(ctx, s.cfg.UID, client, out)
if err != nil {
return
Copy link
Contributor

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.

Copy link
Contributor Author

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()
Copy link
Contributor

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{}.

Copy link
Contributor Author

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.

if err != nil {
s.Log.Print(err)
w.WriteHeader(http.StatusInternalServerError)
return
}

jDir, err := ioutil.ReadDir(jPath)
buildLog, err = ioutil.ReadFile(buildLogPath)
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

w.WriteHeader(http.StatusInternalServerError)
return
}
err = json.Unmarshal(biBlob, &bi)
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, handled.

w.WriteHeader(http.StatusInternalServerError)
return
}
err = json.Unmarshal(biBlob, &bi)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

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 {
Copy link
Contributor

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?

Copy link
Contributor Author

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'.
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -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) {
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

ID: j.Name(),
Project: p.Name(),
StartedAt: bi.StartedAt,
State: "ready"})
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@apostergiou apostergiou force-pushed the fix-dir-modtime branch 2 times, most recently from 6743d79 to 0c6a214 Compare April 24, 2018 06:11
@@ -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) {
Copy link
Contributor

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).

Copy link
Contributor Author

@apostergiou apostergiou Apr 25, 2018

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>";
Copy link
Contributor

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

Copy link
Contributor Author

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)
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

pendingExists := !os.IsNotExist(err)
readyPath := filepath.Join(s.cfg.BuildPath, p.Name(), "ready")
_, err = os.Stat(readyPath)
readyExists := !os.IsNotExist(err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto.

Copy link
Contributor Author

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,
Copy link
Contributor

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?

Copy link
Contributor Author

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)
}
Copy link
Contributor

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...)
// ...

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah true.

@apostergiou apostergiou merged commit dd45d61 into master Apr 25, 2018
@apostergiou apostergiou deleted the fix-dir-modtime branch April 25, 2018 11:25
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working server
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants