Spaces:
Sleeping
Sleeping
Update static/API_Refresh_workerJS.js
Browse files
static/API_Refresh_workerJS.js
CHANGED
|
@@ -1,6 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
intervalBegin()
|
| 2 |
|
| 3 |
|
|
|
|
| 4 |
function intervalBegin(){
|
| 5 |
// minutes= min *60*1000
|
| 6 |
intervalAPI= setInterval( getRefreshAPIAjax ,1800000) // 30*60*1000 // every 30 min
|
|
@@ -9,13 +26,23 @@ function intervalBegin(){
|
|
| 9 |
|
| 10 |
function getRefreshAPIAjax(){
|
| 11 |
|
| 12 |
-
|
|
|
|
| 13 |
.then(function(data) {
|
| 14 |
self.postMessage(data); // Code depending on result
|
| 15 |
})
|
| 16 |
}
|
| 17 |
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
return new Promise(function(resolve, reject) {
|
| 21 |
var xhr = new XMLHttpRequest();
|
|
@@ -23,17 +50,23 @@ function ajax(url , sectionData) {
|
|
| 23 |
resolve(this.responseText);
|
| 24 |
};
|
| 25 |
xhr.onerror = reject;
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
// xhr.send("sectionData=" + sectionData);
|
| 29 |
xhr.open('GET', url)//+'?sectionData=' + sectionData);
|
| 30 |
-
xhr.send();
|
|
|
|
| 31 |
});
|
| 32 |
}
|
| 33 |
|
| 34 |
|
| 35 |
function appendtotables(data){
|
| 36 |
-
ajax('/refreshAPIAppendNewTables
|
| 37 |
.then(function(data) {
|
| 38 |
console.log('ok')
|
| 39 |
// self.postMessage('appended'); // Code depending on result
|
|
|
|
| 1 |
+
var prjname=''
|
| 2 |
+
var prjpart=''
|
| 3 |
+
self.onmessage = function(event) {
|
| 4 |
+
console.log('Message received from main script:', event.data);
|
| 5 |
+
console.log(typeof event.data)
|
| 6 |
+
if (typeof event.data === 'object')
|
| 7 |
+
{
|
| 8 |
+
prjname=event.data[0]
|
| 9 |
+
prjpart=event.data[1]
|
| 10 |
+
console.log(prjname,prjpart)
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
else
|
| 14 |
+
prjname=event.data
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
intervalBegin()
|
| 18 |
|
| 19 |
|
| 20 |
+
|
| 21 |
function intervalBegin(){
|
| 22 |
// minutes= min *60*1000
|
| 23 |
intervalAPI= setInterval( getRefreshAPIAjax ,1800000) // 30*60*1000 // every 30 min
|
|
|
|
| 26 |
|
| 27 |
function getRefreshAPIAjax(){
|
| 28 |
|
| 29 |
+
console.log(prjname,'jgjk')
|
| 30 |
+
ajax("/refreshAPI",prjname,prjpart)//, sectionData)
|
| 31 |
.then(function(data) {
|
| 32 |
self.postMessage(data); // Code depending on result
|
| 33 |
})
|
| 34 |
}
|
| 35 |
|
| 36 |
+
|
| 37 |
+
// function getRefreshAPIPartAjax(prjname){
|
| 38 |
+
|
| 39 |
+
// ajax("/getnewparts",prjname)//, sectionData)
|
| 40 |
+
// .then(function(data) {
|
| 41 |
+
// self.postMessage(data); // Code depending on result ['parts',data]
|
| 42 |
+
// })
|
| 43 |
+
// }
|
| 44 |
+
|
| 45 |
+
function ajax(url , prjname=0) {
|
| 46 |
|
| 47 |
return new Promise(function(resolve, reject) {
|
| 48 |
var xhr = new XMLHttpRequest();
|
|
|
|
| 50 |
resolve(this.responseText);
|
| 51 |
};
|
| 52 |
xhr.onerror = reject;
|
| 53 |
+
if (prjname){
|
| 54 |
+
console.log('gss',prjname,prjpart)
|
| 55 |
+
xhr.open('GET', url+'?prjname=' + prjname+'&prjpart=' + prjpart );
|
| 56 |
+
xhr.send();
|
| 57 |
+
}
|
| 58 |
+
else
|
| 59 |
+
{// xhr.open('POST', url, true);
|
| 60 |
// xhr.send("sectionData=" + sectionData);
|
| 61 |
xhr.open('GET', url)//+'?sectionData=' + sectionData);
|
| 62 |
+
xhr.send();}
|
| 63 |
+
|
| 64 |
});
|
| 65 |
}
|
| 66 |
|
| 67 |
|
| 68 |
function appendtotables(data){
|
| 69 |
+
ajax('/refreshAPIAppendNewTables', true)
|
| 70 |
.then(function(data) {
|
| 71 |
console.log('ok')
|
| 72 |
// self.postMessage('appended'); // Code depending on result
|