Skip to content

Commit 88253b5

Browse files
show better job state and add some filters
1 parent 5b72456 commit 88253b5

File tree

2 files changed

+71
-42
lines changed

2 files changed

+71
-42
lines changed

.env.development

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VUE_APP_API_URL=http://localhost:808
1+
VUE_APP_API_URL=https://github-autoscaler.ethquokkaops.io

src/components/Runners.vue

+70-41
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
<template>
22
<div>
33
<h1>Runners Overview</h1>
4+
<div>
5+
<p>Search for runner: <input type="text" v-model="searchRunner" placeholder="runner name" /></p>
6+
<p><input type="checkbox" v-model.lazy="searchOnlyOnline" id="online"/><label for="online">Show only online runners</label></p>
7+
</div>
48
<table>
59
<thead>
610
<tr>
@@ -19,8 +23,7 @@
1923
<template v-for="runner in sortedRunners" :key="runner.runnerId">
2024
<tr>
2125
<td>{{ getStatusIcon(runner.isOnline)}} <a target="_blank" title="Show monitoring" :href="'https://grafana.ethquokkaops.io/d/rYdddlPWk/node-exporter-full?orgId=1&var-DS_PROMETHEUS=default&var-job=integrations%2Fnode_exporter&var-node='+ runner.hostname +':9090'">📈</a> {{ runner.hostname }}</td>
22-
<td v-if="runner.jobId">🚀 Job assigned</td>
23-
<td v-else>🔎 No job assigned</td>
26+
<td>{{ getRunnerJobState(runner)}}</td>
2427
<td><a :href="'https://github.com/' + runner.owner" target="_blank">{{ runner.owner }}</a></td>
2528
<td>{{ runner.size }}</td>
2629
<td><code>{{ runner.iPv4 }}</code></td>
@@ -99,23 +102,47 @@ export default {
99102
return {
100103
runners: [],
101104
visibleRunners: [],
102-
jobs: []
105+
jobs: [],
106+
searchRunner: "",
107+
searchOnlyOnline: false
103108
};
104109
},
105110
mounted() {
106111
this.fetchRunners();
107-
setInterval(this.fetchRunners, 2000);
112+
setInterval(this.fetchRunners, 10000);
108113
},
109114
computed: {
110115
sortedRunners() {
111-
return this.runners.map(runner => ({
116+
console.log("Triggered compute")
117+
return this.runners
118+
.filter(runner => {
119+
if(this.searchOnlyOnline === true) {
120+
return runner.isOnline && runner.hostname.includes(this.searchRunner)
121+
} else {
122+
return runner.hostname.includes(this.searchRunner)
123+
}
124+
})
125+
.map(runner => ({
112126
...runner,
113127
lifecycle: runner.lifecycle.slice().sort((a, b) => new Date(a.eventTimeUtc) - new Date(b.eventTimeUtc)),
114128
job: this.jobs.find(j => j.runnerId === runner.runnerId)
115129
}));
116130
}
117131
},
118132
methods: {
133+
getRunnerJobState(runner) {
134+
if(runner.jobId) {
135+
if(runner.job) {
136+
return this.getJobState(runner.job.db.state);
137+
}
138+
else {
139+
return "welp"
140+
}
141+
}
142+
else {
143+
return "🔎 No job assigned";
144+
}
145+
},
119146
getCommitUrl(sha, repo) {
120147
return "https://github.com/" + repo + "/commit/" + sha
121148
},
@@ -144,62 +171,64 @@ export default {
144171
getJobState(statusCode) {
145172
const JobState = {
146173
0: "Unknown",
147-
1: "Queued",
148-
2: "In Progress",
149-
3: "Completed"
174+
1: "⏸️ Queued",
175+
2: "▶️ In Progress",
176+
3: "Completed"
150177
};
151178
if (Object.prototype.hasOwnProperty.call(JobState, statusCode)) {
152179
return JobState[statusCode];
153180
}
154181
return "Unknown"; // Default case if status code is not found
155182
156183
},
157-
fetchRunners() {
158-
axios.get(process.env.VUE_APP_API_URL + '/api/get-runners')
159-
.then(response => {
160-
this.runners = response.data;
161-
for(var od of this.visibleRunners) {
162-
let r = this.runners.find(x => x.runnerId === od)
163-
this.fetchJob(r.jobId, od)
164-
}
184+
async fetchRunners() {
185+
let runnerResp = await axios.get(process.env.VUE_APP_API_URL + '/api/get-runners');
186+
this.runners = runnerResp.data;
187+
188+
// Fetch job infos
189+
for(var r of this.runners) {
190+
if(r.jobId) {
191+
let loadGh = this.visibleRunners.includes(r.runnerId)
192+
await this.fetchJob(r.jobId, r.runnerId, loadGh)
193+
}
194+
}
165195
166-
})
167-
.catch(error => {
168-
console.error('There was an error fetching the runners:', error);
169-
});
170196
},
171-
fetchJob(jobid,runnerid) {
197+
async fetchJob(jobid,runnerid, withGithub) {
172198
if(!jobid) { return }
173-
axios.get(process.env.VUE_APP_API_URL + '/api/get-job/'+jobid)
174-
.then(response => {
175-
const index = this.jobs.findIndex(job => job.runnerId === runnerid);
199+
let jobDb = await axios.get(process.env.VUE_APP_API_URL + '/api/get-job/'+jobid);
176200
177-
if (index !== -1) {
178-
this.jobs.splice(index, 1);
179-
}
201+
const index = this.jobs.findIndex(job => job.runnerId === runnerid);
202+
203+
if (index !== -1) {
204+
this.jobs.splice(index, 1);
205+
}
180206
181-
this.jobs.push({
182-
runnerId: runnerid,
183-
db: response.data,
184-
gh: {}
185-
})
186-
axios.get(response.data.jobUrl).then(resp => {
187-
let j = this.jobs.find(j => j.runnerId === runnerid);
188-
j['gh'] = resp.data;
189-
})
207+
this.jobs.push({
208+
runnerId: runnerid,
209+
db: jobDb.data,
210+
gh: {}
211+
})
212+
213+
if(withGithub) {
214+
try {
215+
let resp = await axios.get(jobDb.data.jobUrl);
216+
let j = this.jobs.find(j => j.runnerId === runnerid);
217+
j['gh'] = resp.data;
218+
}
219+
catch {
220+
console.log("unable to query github")
221+
}
222+
}
190223
191-
})
192-
.catch(error => {
193-
console.error('There was an error fetching the runners:', error);
194-
});
195224
196225
},
197226
toggleDetails(id,jobid) {
198227
const index = this.visibleRunners.indexOf(id);
199228
if (index > -1) {
200229
this.visibleRunners.splice(index, 1);
201230
} else {
202-
this.fetchJob(jobid,id)
231+
this.fetchJob(jobid,id,true)
203232
this.visibleRunners.push(id);
204233
}
205234
}

0 commit comments

Comments
 (0)