2019-08-16 12:54:29 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.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();
|
|
|
|
})
|
2019-08-19 15:09:01 +00:00
|
|
|
.then(function(json) {
|
|
|
|
var delta = jsondiffpatch.diff(jobs, json);
|
|
|
|
if (delta) {
|
|
|
|
jobs = json;
|
2019-08-16 12:54:29 +00:00
|
|
|
for (subscriber of subscribers.jobs) {
|
2019-08-19 15:09:01 +00:00
|
|
|
subscriber(delta);
|
2019-08-16 12:54:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(function(error) {
|
|
|
|
console.log('Request failed', error);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
setInterval(getCorpora, 5000);
|
|
|
|
setInterval(getJobs, 5000);
|