I’m running an HTTP request when meteor starts from main.js on the server.
I want this request to run again on a timer, so I have set a simple setTimeout function to run it again.
Each time I run the meteor
command to start the server the function runs fine and I get the results I expect. But when the timer elapses and it tries to run again I get this error:
Error: Can't wait without a fiber
Here’s my function on the server. Any help is appreciated. I saw some stuff about async, but don’t really understand. I’m not sure how to set the async / await in this function, and don’t grasp why it runs fine the first time.
checkURLsRepeat = function() {
try {
console.log("-------- --------- --------");
console.log("Setting up the next Check.");
let status = "";
// code to run on server at startup
let checkURLs = URLToCheck.find({}).fetch();
if (typeof checkURLs != 'undefined' && checkURLs != "" && checkURLs != null) {
for (i=0; i < checkURLs.length; i++) {
let myURL = checkURLs[i].url;
HTTP.get(myURL, {mode: 'no-cors'}, function(err, result){
if (err) {
console.log("Error:" + myURL + " " + err);
} else {
// console.dir(result);
if (result.statusCode == 200) {
let status = "Up";
console.log("Success!");
Meteor.call('hostStatus.add', myURL, status, "#32CD32");
} else if (result.statusCode == 400) {
let status = "Bad REquest";
console.log("Success! Bad Request Returned.");
Meteor.call('hostStatus.add', myURL, status, "#32CD32");
} else if (result.statusCode == 401) {
let status = "Authorization Required";
console.log("Success! Authorization Required.");
Meteor.call('hostStatus.add', myURL, status, "#ff0000");
} else if (result.statusCode == 402) {
let status = "Payment Required";
console.log("Success! Payment Required.");
Meteor.call('hostStatus.add', myURL, status, "#ff0000");
} else if (result.statusCode == 403) {
let status = "Access Forbidden";
console.log("Success! Access Forbidden.");
Meteor.call('hostStatus.add', myURL, status, "#32CD32");
} else if (result.statusCode == 404) {
let status = "Not Found!";
console.log("Not Found! Site may be down!");
Meteor.call('hostStatus.add', myURL, status, "#ff0000");
// this should trigger an alert.
} else if (result.statusCode == 405) {
let status = "Method Not Allowed";
console.log("Success! Method Not Allowed");
Meteor.call('hostStatus.add', myURL, status, "#32CD32");
} else if (result.statusCode == 406) {
let status = "Not Acceptable";
console.log("Host May Be Down! Not Acceptable.");
Meteor.call('hostStatus.add', myURL, status, "#FFA500");
} else if (result.statusCode == 407) {
let status = "Proxy Authentication Required";
console.log("Success! Proxy Authentication Required.");
Meteor.call('hostStatus.add', myURL, status, "#FFA500");
} else if (result.statusCode == 408) {
let status = "Request Timeout";
console.log("Host May Be Down! Request Timeout");
Meteor.call('hostStatus.add', myURL, status, "#FFA500");
} else if (result.statusCode == 409) {
let status = "Conflict";
console.log("Host May Be Down! Conflict");
Meteor.call('hostStatus.add', myURL, status, "#FFA500");
} else if (result.statusCode == 410) {
let status = "Gone";
console.log("Host May Be Down! Gone");
Meteor.call('hostStatus.add', myURL, status, "#FFA500");
} else if (result.statusCode == 414) {
let status = "Request URL Too Large";
console.log("Error! Request URL Too Large.");
Meteor.call('hostStatus.add', myURL, status, "#FF0000");
} else if (result.statusCode == 500) {
let status = "Internal Server Error";
console.log("Site Inoperative. Internal Server Error.");
Meteor.call('hostStatus.add', myURL, status, "#FF0000");
}
}
});
}
} else {
console.log("Didn't find any URLs to Check at this time.");
}
return;
} catch (error) {
console.log("Error Occurred: " + error);
}
}