nopaque/app/static/js/polls.js

58 lines
1.3 KiB
JavaScript
Raw Normal View History

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();
})
.then(function(data) {
if (JSON.stringify(jobs) != JSON.stringify(data)) {
jobs = data;
for (subscriber of subscribers.jobs) {
subscriber();
}
}
})
.catch(function(error) {
console.log('Request failed', error);
});
}
setInterval(getCorpora, 5000);
setInterval(getJobs, 5000);