-
Notifications
You must be signed in to change notification settings - Fork 519
Expand file tree
/
Copy pathJobSummaryStore.js
More file actions
112 lines (98 loc) · 2.8 KB
/
Copy pathJobSummaryStore.js
File metadata and controls
112 lines (98 loc) · 2.8 KB
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
import {observable, computed, runInAction} from 'mobx';
import JobSummaryModel from '../models/JobSummaryModel'
import $ from 'jquery'
export class JobSummaryStore {
@observable jobSummarys = new Array
@observable isLoading = true
constructor() {
this.loadJobSummarys();
}
@computed get successCount() {
return this.jobSummarys.reduce(
(sum, job) => sum + (job.status === 'success' ? 1 : 0),
0
)
}
@computed get failureCount() {
return this.jobSummarys.reduce(
(sum, job) => sum + (job.status === 'failure' ? 1 : 0),
0
)
}
@computed get freshCount() {
return this.jobSummarys.reduce(
(sum, job) => sum + (job.status === 'fresh' ? 1 : 0),
0
)
}
@computed get queuedCount() {
return this.jobSummarys.reduce(
(sum, job) => sum + (job.state === 'queued' ? 1 : 0),
0
)
}
@computed get idleCount() {
return this.jobSummarys.reduce(
(sum, job) => sum + (job.state === 'idle' ? 1 : 0),
0
)
}
@computed get runningCount() {
return this.jobSummarys.reduce(
(sum, job) => sum + (job.state.match(/\d+ running/) ? 1 : 0),
0
)
}
@computed get jobNames() {
var names = []
this.jobSummarys.forEach(j => {
names.push(j.name)
})
return names
}
/**
* Update a jobSummary with information from the server. Guarantees a jobSummary
* only exists once. Might either construct a new jobSummary, update an existing one,
* or remove a jobSummary if it has been deleted on the server.
*/
updateJobSummaryFromServer(json) {
var jobSummary = this.jobSummarys.find(jobSummary => jobSummary.name === json.name);
if (!jobSummary) {
jobSummary = JobSummaryModel.fromJS(this, json);
this.jobSummarys.push(jobSummary);
}
jobSummary.updateFromJson(json);
}
/**
* Fetches all jobSummary's from the server
*/
loadJobSummarys() {
this.isLoading = true;
var otherThis = this;
$.getJSON('v1/scheduler/jobs/summary').done(function(resp) {
runInAction("update job summaries", () => {
var serverJobNames = new Set();
resp.jobs.forEach(json => {
serverJobNames.add(json.name)
otherThis.updateJobSummaryFromServer(json)
});
// Check for jobs which exist here, but not on the server
otherThis.jobSummarys.filter(function(j) {
return !serverJobNames.has(j.name)
}).forEach(j => j.destroy())
otherThis.isLoading = false;
});
}).fail(function() {
otherThis.isLoading = false;
});
setTimeout(function() {
otherThis.loadJobSummarys();
}, 2000);
}
/**
* A jobSummary was somehow deleted, clean it from the client memory
*/
removeJobSummary(jobSummary) {
this.jobSummarys.splice(this.jobSummarys.indexOf(jobSummary), 1);
}
}