Skip to content

Commit

Permalink
now also add duration to ui, closes #45
Browse files Browse the repository at this point in the history
  • Loading branch information
bart6114 committed Oct 25, 2023
1 parent d288d15 commit 75f2c87
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 8 deletions.
10 changes: 9 additions & 1 deletion pkg/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"net/http"
"sort"
"strings"
"time"
)

type Response struct {
Expand Down Expand Up @@ -123,8 +124,15 @@ func ui(s *Schedule) func(w http.ResponseWriter, r *http.Request) {
}
sort.Strings(jobNames)

// add custom functions to template
funcMap := template.FuncMap{
"roundToSeconds": func(d time.Duration) int {
return int(d.Seconds())
},

Check warning on line 131 in pkg/http.go

View check run for this annotation

Codecov / codecov/patch

pkg/http.go#L130-L131

Added lines #L130 - L131 were not covered by tests
}

// parse template files
tmpl, err := template.ParseFS(fsys(), "*.html")
tmpl, err := template.New("index.html").Funcs(funcMap).ParseFS(fsys(), "*.html")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
Expand Down
2 changes: 1 addition & 1 deletion pkg/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<div class="row">
<div class="col-12">
<div class="flex-container">
{{range .JobNames}}<a class="{{if eq . $.SelectedJobName}}text-primary{{else}}text-grey{{end}} pad"
{{range .JobNames}}<a class="{{if eq . $.SelectedJobName}}text-primary{{else}}text-dark{{end}} pad"
href="/job/{{.}}">{{.}}</a>{{end}}
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion pkg/public/jobview.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ <h4 class="is-marginless view-header text-primary">JobSpec</h4>
</div>
<div class="view-container">
<h4 class="is-marginless view-header text-primary">Logs</h4>
<pre class="pre-wrap">{{range $i, $j := .SelectedJobSpec.Runs}}<span id="log{{$i}}"></span>{{.TriggeredAt}} | triggered by: {{ .TriggeredBy }} | exit code: {{.Status}}
<pre class="pre-wrap">{{range $i, $j := .SelectedJobSpec.Runs}}<span id="log{{$i}}"></span>{{.TriggeredAt}} | triggered by: {{ .TriggeredBy }} | duration: {{ .Duration | roundToSeconds}}s | exit code: {{.Status}}
---
{{.Log}}
{{end}}
Expand Down
6 changes: 3 additions & 3 deletions pkg/public/overview.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{{ define "overview"}} {{range .JobNames}} {{ $spec := index $.JobSpecs .}}
<div class="inline">
<a class="text-grey pad" href="/job/{{$spec.Name}}">{{$spec.Name}}</a>
<a class="text-dark pad" href="/job/{{$spec.Name}}">{{$spec.Name}}</a>
{{ range $i, $r := $spec.Runs }}
<a href="/job/{{$spec.Name}}#log{{$i}}"
><abbr class="no-underline" title="{{$r.TriggeredAt.Format "2006-01-02T15:04:05"}}&#10;exit code: {{$r.Status}}"
><abbr class="no-underline" title="{{$r.TriggeredAt.Format "2006-01-02T15:04:05"}}&#10;duration: {{$r.Duration | roundToSeconds}}s&#10;exit code: {{$r.Status}}"
>{{ if eq $r.Status 0 }}
<img src="/static/img/circle.svg" />
{{else}}
Expand All @@ -14,5 +14,5 @@
{{end}}
</div>
{{end}}
<p class="text-grey pad-top"><small>shows statuses up until the last 10 runs</small></p>
<p class="text-dark pad-top"><small>shows statuses up until the last 10 runs</small></p>
{{ end }}
4 changes: 2 additions & 2 deletions pkg/public/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
body.dark {
--bg-color: #000;
--bg-secondary-color: #131316;
--font-color: #f5f5f5;
--font-color: #d3d7cf;
--color-grey: #ccc;
--color-darkGrey: #777;
--color-darkGrey: #d3d7cf;
}

.button.icon-only {
Expand Down
4 changes: 4 additions & 0 deletions testdata/sleep.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
jobs:
sleep_3_command:
cron: "* * * * *"
command: sleep 3

0 comments on commit 75f2c87

Please sign in to comment.