-
Notifications
You must be signed in to change notification settings - Fork 0
/
.sse_tester2.html
42 lines (38 loc) · 1.13 KB
/
.sse_tester2.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<link rel="icon" href="data:," />
<title>Document</title>
</head>
<body>
<h1>SSE Tester</h1>
<p>
This html/js is just to test a call to trigger the server-side async worker and then listen to the SSE route
for that job to finish.
</p>
<script>
const base_url = 'http://127.0.0.1:5003/catch-local';
let awaitedJobUuid;
// Begin listening to SSE route
const source = new EventSource(base_url + '/stream/');
source.onmessage = function(e) {
console.log('>>>>>>>>>>>>>>>');
console.log(e, awaitedJobUuid);
if (e.data === awaitedJobUuid) {
this.close(); // Sever connection to SSE route
console.log('Events matched!!!', this.CLOSED);
}
};
// Call route to start worker running
const pingWorker = async () => {
const res = await fetch(base_url + '/demo/redis/');
const data = await res.json();
awaitedJobUuid = data.job_uuid;
};
pingWorker();
</script>
</body>
</html>