generated from rizalgowandy/library-template-go
-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathjobs.go
246 lines (241 loc) · 7.78 KB
/
jobs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
package page
import (
"html/template"
"sync"
)
const jobsTemplate = `
<!--
This page is only being used for development to restructure the code,
the real html page is on jobs.go.
-->
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Standard Meta -->
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta http-equiv="refresh" content="30"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<!-- Site Properties -->
<title>Cronx</title>
<link
rel="stylesheet"
type="text/css"
href="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.css">
<script
src="https://code.jquery.com/jquery-3.1.1.min.js"
integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8="
crossorigin="anonymous"></script>
<script
src="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.js"
crossorigin="anonymous"></script>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.5.0-beta4/html2canvas.min.js"
integrity="sha512-OqcrADJLG261FZjar4Z6c4CfLqd861A3yPNMb+vRQ2JwzFT49WT4lozrh3bcKxHxtDTgNiqgYbEUStzvZQRfgQ=="
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/canvas2image@1.0.5/canvas2image.min.js"></script>
<script type='text/javascript'>
function screenshot() {
html2canvas(document.querySelector('#data_table')).then(function(canvas) {
Canvas2Image.saveAsPNG(canvas, canvas.width, canvas.height);
});
}
</script>
<style>
body > .ui.container {
margin-top: 3em;
padding-bottom: 3em;
}
</style>
<title>Cronx</title>
</head>
<body>
<div class="ui container">
<div class="ui left fixed vertical stackable inverted main menu">
<div class="header item">
<i class="stopwatch icon"></i>
Cronx
</div>
<a class="item active" href="javascript:window.location.reload()">
<i class="tasks icon"></i>
Jobs
</a>
<a class="item" href="/histories">
<i class="history icon"></i>
Histories
</a>
<div class="item" onclick="screenshot()">
<button class="fluid ui labeled inverted green icon button">
<i class="camera icon"></i>
<div class="left aligned">Screenshot</div>
</button>
</div>
</div>
<div class="ui five steps">
<div class="step">
<i class="arrow down icon"></i>
<div class="content">
<div class="title">Down</div>
<div class="description">Job fails to be registered</div>
</div>
</div>
<div class="step">
<i class="arrow up icon"></i>
<div class="content">
<div class="title">Up</div>
<div class="description">Job has just been created</div>
</div>
</div>
<div class="step">
<i class="sync icon"></i>
<div class="content">
<div class="title">Running</div>
<div class="description">Job is currently running</div>
</div>
</div>
<div class="step">
<i class="hourglass end icon"></i>
<div class="content">
<div class="title">Success</div>
<div class="description">Job succeeds on the last run, waiting for next run</div>
</div>
</div>
<div class="step">
<i class="attention icon"></i>
<div class="content">
<div class="title">Error</div>
<div class="description">Job fails on the prev run</div>
</div>
</div>
</div>
<div id="data_table">
<table class="ui sortable selectable center aligned celled table">
<thead>
<tr>
<th id="id"
{{if eq (index .Sort.Columns "id") "ASC"}} class="sorted ascending"
{{else if eq (index .Sort.Columns "id") "DESC"}} class="sorted descending"
{{end}}
>ID
</th>
<th id="name"
{{if eq (index .Sort.Columns "name") "ASC"}} class="sorted ascending"
{{else if eq (index .Sort.Columns "name") "DESC"}} class="sorted descending"
{{end}}
>Name
</th>
<th id="status"
{{if eq (index .Sort.Columns "status") "ASC"}} class="sorted ascending"
{{else if eq (index .Sort.Columns "status") "DESC"}} class="sorted descending"
{{end}}
>Status
</th>
<th id="prev_run"
{{if eq (index .Sort.Columns "prev_run") "ASC"}} class="sorted ascending"
{{else if eq (index .Sort.Columns "prev_run") "DESC"}} class="sorted descending"
{{end}}
>Prev run
</th>
<th id="next_run"
{{if eq (index .Sort.Columns "next_run") "ASC"}} class="sorted ascending"
{{else if eq (index .Sort.Columns "next_run") "DESC"}} class="sorted descending"
{{end}}
>Next run
</th>
<th id="latency"
{{if eq (index .Sort.Columns "latency") "ASC"}} class="sorted ascending"
{{else if eq (index .Sort.Columns "latency") "DESC"}} class="sorted descending"
{{end}}
>Latency
</th>
</tr>
</thead>
<tbody>
{{if not .Data}}
<tr>
<td colspan="6" class="center aligned"><b><i>No records found.</i></b></td>
</tr>
{{end}}
{{range .Data}}
<tr
{{if eq .Job.Status "RUNNING"}} class="warning"
{{else if eq .Job.Status "SUCCESS"}} class="positive"
{{else if eq .Job.Status "DOWN"}} class="error"
{{else if eq .Job.Status "ERROR"}} class="error"
{{end}}
>
<td>{{.ID}}</td>
<td class="left aligned">
{{if gt .Job.TotalWave 1 }}
{{.Job.Name}} ({{.Job.Wave}}/{{.Job.TotalWave}})
{{else}}
{{.Job.Name}}
{{end}}
</td>
<td>
{{if eq .Job.Status "RUNNING"}}
<div class="ui yellow label">
{{.Job.Status}}
</div>
{{else if eq .Job.Status "SUCCESS"}}
<div class="ui green label">
{{.Job.Status}}
</div>
{{else if eq .Job.Status "DOWN"}}
<div class="ui red label">
{{.Job.Status}}
</div>
{{else if eq .Job.Status "ERROR"}}
<div class="ui red label">
{{.Job.Status}}
</div>
{{else}}
<div class="ui label">
{{.Job.Status}}
</div>
{{end}}
</td>
<td>
{{if eq .Job.Status "ERROR"}}
{{if not .Prev.IsZero}}
{{.Prev.Format "2006-01-02 15:04:05"}}
{{end}}
<br/>
{{.Job.Error}}
{{else}}
{{if not .Prev.IsZero}}
{{.Prev.Format "2006-01-02 15:04:05"}}
{{end}}
{{end}}
</td>
<td>
{{if eq .Job.Status "DOWN"}}
{{.Job.Error}}
{{else}}
{{if not .Next.IsZero}}
{{.Next.Format "2006-01-02 15:04:05"}}
{{end}}
{{end}}
</td>
<td>{{.Job.Latency}}</td>
</tr>
{{end}}
</tbody>
</table>
</div>
</div>
</body>
</html>
`
var (
jobsPageOnce sync.Once
jobsPage *template.Template
jobsPageError error
)
func GetJobsPageTemplate() (*template.Template, error) {
jobsPageOnce.Do(func() {
t := template.New(jobsTemplateName)
jobsPage, jobsPageError = t.Parse(jobsTemplate)
})
return jobsPage, jobsPageError
}