Stop polling. Use SocketIO!

This commit is contained in:
Patrick Jentsch
2019-08-23 15:05:01 +02:00
parent 3d8b8e9182
commit 7aef3de81d
12 changed files with 58 additions and 5120 deletions

View File

@ -1,10 +1,12 @@
class CorpusList extends List {
constructor(idOrElement, options, live=false) {
constructor(idOrElement, options) {
super(idOrElement, options);
corporaSubscribers.push(this);
}
init() {
this.createCorpusElements(corpora);
if (live) {
subscribers.corpora.push(this);
}
}
@ -48,7 +50,7 @@ class CorpusList extends List {
List.updatePagination(this);
}
/*
corporaUpdateHandler(delta) {
var corpusElement, key, listItem;
@ -76,4 +78,5 @@ class CorpusList extends List {
}
}
}
*/
}

View File

@ -1,10 +1,12 @@
class JobList extends List {
constructor(idOrElement, options, live=false) {
constructor(idOrElement, options) {
super(idOrElement, options);
jobsSubscribers.push(this);
}
init() {
this.createJobElements(jobs);
if (live) {
subscribers.jobs.push(this);
}
}
@ -51,7 +53,7 @@ class JobList extends List {
List.updatePagination(this);
}
/*
jobsUpdateHandler(delta) {
var jobElement, jobStatusElement, key, listItem;
@ -85,6 +87,7 @@ class JobList extends List {
}
}
}
*/
}
JobList.SERVICE_COLORS = {"nlp": "blue",

File diff suppressed because it is too large Load Diff

View File

@ -1,58 +0,0 @@
var subscribers = {"corpora": [], "jobs": []};
function getCorpora() {
fetch("/api/v1.0/corpora")
.then(function(response) {
if (response.status >= 200 && response.status < 300) {
return Promise.resolve(response);
} else {
return Promise.reject(new Error(response.statusText));
}
})
.then(function(response) {
return response.json();
})
.then(function(data) {
if (JSON.stringify(corpora) != JSON.stringify(data)) {
corpora = data;
for (subscriber of subscribers.corpora) {
subscriber.corporaUpdateHandler();
}
}
})
.catch(function(error) {
console.log('Request failed', error);
});
}
function getJobs() {
fetch("/api/v1.0/jobs")
.then(function(response) {
if (response.status >= 200 && response.status < 300) {
return Promise.resolve(response);
} else {
return Promise.reject(new Error(response.statusText));
}
})
.then(function(response) {
return response.json();
})
.then(function(json) {
var delta = jsondiffpatch.diff(jobs, json);
if (delta) {
jobs = json;
for (subscriber of subscribers.jobs) {
subscriber.jobsUpdateHandler(delta);
}
}
})
.catch(function(error) {
console.log('Request failed', error);
});
}
setInterval(getCorpora, 5000);
setInterval(getJobs, 5000);