- Add a retry loop when the server is down
This commit is contained in:
Logan Cusano
2023-06-23 17:55:08 -04:00
parent 7163df21e9
commit fb9df3230e

View File

@@ -106,8 +106,18 @@ exports.checkIn = async () => {
if (!runningClientConfig?.id || runningClientConfig.id == 0) {
// ID was not found in the config, creating a new node
reqOptions = new requestOptions("/nodes/newNode", "POST");
sendHttpRequest(reqOptions, JSON.stringify(runningClientConfig), async (responseObject) => {
// Update the client's ID if the server accepted it
sendHttpRequest(reqOptions, JSON.stringify(runningClientConfig), async (responseObject) => {
// Check if the server responded
if (!responseObject) {
log.WARN("Server did not respond to checkIn. Will wait 60 seconds then try again");
setTimeout(() => {
// Run itself again to see if the server is up now
this.checkIn();
}, 60000);
return
}
// Update the client's ID if the server accepted its
if (responseObject.statusCode === 202) {
runningClientConfig.id = responseObject.body.nodeId;
log.DEBUG("Response object from new node: ", responseObject, runningClientConfig);