-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
243 lines (211 loc) · 6.8 KB
/
index.html
File metadata and controls
243 lines (211 loc) · 6.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
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
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8" />
<style>
.boxes
{
font-family: monospace;
height: 330px;
width: 300px;
}
#ccu
{
border-bottom-color: black;
border-right-color: black;
border-left-color: #808080;
background-color: #3D3D3D;
border-top-color: #808080;
border-radius: 3px;
padding-right: 12px;
padding-top: 12px;
padding-left: 6px;
font-family: monospace;
height: 30px;
border: 1px solid;
width: 250px;
color: #CCCCFF;
}
#ccuIndicator
{
border-bottom-color: #666666;
border-right-color: #666666;
border-left-color: #C0C0C0;
border-top-color: #C0C0C0;
border-radius: 8px;
border: 1px solid;
width: 16px;
float: right;
}
#ccuMPT
{
background-color: #660000;
padding-right: 2px;
padding-left: 2px;
color: lime;
}
#mainTable
{
border-collapse: collapse
margin: auto;
width: 80%;
}
</style>
</head>
<body>
<p><br /></p>
<table id="mainTable" >
<tr style="height: 100px;">
<td>
<button id="addTask" onclick="addTasks(1)">Add Task</button>
<button id="addTask" onclick="addTasks(10)">Add 10 Tasks</button>
<button id="addTask" onclick="addTasks(100)">Add 100 Tasks</button>
</td>
<td>
<div id="ccu">Controller <span id="ccuMPT">MPT: 3</span><span id="ccuIndicator" style="background-color: #008000"> </span></div>
</td>
<td><span id="ls"> <p><br></p> </span></td>
</tr>
<tr>
<td>
QUEUE (<span id="ql">0</span>)
</td>
<td>
INSTANCES (<span id="il">0</span>)
</td>
<td>
LOG
</td>
</tr>
<tr>
<td>
<textarea id="queue" class="boxes" spellcheck="false"></textarea>
</td>
<td>
<textarea id="instances" class="boxes" spellcheck="false"></textarea>
</td>
<td>
<div id="log" class="boxes" style="border: solid 1px black; overflow-y: scroll; width: 600px"></div>
</td>
</tr>
</table>
<p><br /></p>
<script type="text/javascript">
// base object
var scala = {
queue: [],
failures: 0,
successes: 0,
instances: []
};
// update once right away
updateFields();
// set interval for controller
var ic = self.setInterval('controller()', 5000);
// add n number of tasks to queue
function addTasks(n){
while(n){
n--;
var neoSessionId = createNewId(8);
var taskCreated = (new Date).toISOString();
scala.queue.push(neoSessionId);
self.log.innerHTML = "Added Task <span style='color:#000080'>" + neoSessionId + "</span> to queue at <span style='color:#990099'>" + taskCreated + "</span><br>" + self.log.innerHTML;
}
updateFields();
}
// update stats and all info
function updateFields(){
// stats
var ts = scala.successes;
var tf = scala.failures;
var tt = ts + tf;
var rs = Math.round(((ts / tt) * 1000)) / 10;
var rf = Math.round(((tf / tt) * 1000)) / 10;
if(tt){
self.ls.innerHTML = "" + ts + " tasks succeed with a success rate of " + rs + "%<br>" + tf + " tasks failed with a failure rate of " + rf + "%<br>" + tt + " total tasks have been processed.";
}
self.ql.innerHTML = scala.queue.length;
self.il.innerHTML = scala.instances.length;
self.queue.value = scala.queue.join("\n");
self.instances.value = scala.instances.join("\n");
}
// base worker process to spawn instances
function controller(){
self.ccuIndicator.style.backgroundColor = "#00FF00";
var maxPerTick = 3;
var queueLength = scala.queue.length;
if(self.maxPerTick){
maxPerTick = self.maxPerTick;
}
var status = "";
if(!queueLength){
status = "<span style='color:gray'>nothing to do</span>";
if(maxPerTick > 5){
maxPerTick = Math.floor(maxPerTick / 2);
}
}
else {
status = "<span style='color:green'>working</span>";
if(queueLength > maxPerTick){
maxPerTick *= 2;
}
else{
if(maxPerTick > 5){
maxPerTick = Math.floor(maxPerTick / 2);
}
}
}
self.maxPerTick = maxPerTick;
self.ccuMPT.innerHTML = "MPT: " + maxPerTick + "";
self.log.innerHTML = "Running Controller..." + status + "...<br>" + self.log.innerHTML;
var i = 0;
// can I haz tasks
while(scala.queue.length && i < maxPerTick){
// launch instances
var task = scala.queue.shift();
var neoInstanceId = createNewId(16);
scala.instances.push("i" + neoInstanceId + " w task " + task);
var tms = Math.floor(Math.random() * 60000);
self.setTimeout("removeInstance('i" + neoInstanceId + "')", tms);
self.log.innerHTML = "Instance <span style='color:green'>" + neoInstanceId + "</span> will run task <span style='color:#000080'>" + task + "</span> for <span style='color:red'>" + Math.round(tms / 1000) + "s</span> <p />" + self.log.innerHTML;
i++;
}
// cleanup
updateFields();
self.setTimeout("self.ccuIndicator.style.backgroundColor = '#008000'",600);
}
function removeInstance(id){
var failureChance = Math.random();
scala.instances.forEach(
function(instance, i){
if(instance.startsWith(id)){
if(failureChance > 0.9){
scala.instances.splice(i, 1);
self.log.innerHTML = "<span style='color:red;font-weight:bold;background-color:yellow;'>PROCESS FAILED</span> Instance <span style='color:green'>" + instance + "</span>...<p />" + self.log.innerHTML;
var taskId = instance.substr(-8,8);
var taskCreated = (new Date).toISOString();
scala.queue.push(taskId);
scala.failures ++;
self.log.innerHTML = "Retry <span style='color:red;font-weight:bold'>FAILED<span> Task <span style='color:#000080'>" + taskId + "</span> to queue at <span style='color:#990099'>" + taskCreated + "</span><p />" + self.log.innerHTML;
}
else {
scala.instances.splice(i, 1);
scala.successes ++;
self.log.innerHTML = "Instance ended with <span style='color:green;font-weight:bold'>SUCCESS</span>: <span style='color:green'>" + instance + "</span>...<p />" + self.log.innerHTML;
}
}
}
);
updateFields();
}
function createNewId(length){
var elements = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
var strLimit = length || 32;
var neoId = "";
for (var i = 0; i < strLimit; i++) { neoId += elements.substr(Math.floor(Math.random() * elements.length), 1); }
return neoId;
}
</script>
</body>
</html>