add invokeid and revert residual cleanup
All checks were successful
Build and push image for doorman-homeassistant / docker (push) Successful in 8s
Build and push Doorman UI / API / docker (push) Successful in 1m22s
Build and push image for doorman-homeassistant / deploy-gitainer (push) Successful in 9s

This commit is contained in:
Martin Dimitrov 2024-10-27 12:09:48 -07:00
parent 6607b306d0
commit 00491528ee

View File

@ -1,6 +1,7 @@
/**
* Doorman entrypoint
*/
const { randomUUID } = require('crypto');
const fetch = require('node-fetch');
async function getConfig(context, buzzer) {
@ -42,7 +43,9 @@ function dialFallbackTwiml(twiml, config) {
}
exports.handler = async function(context, event, callback) {
let invokeId = `[${randomUUID()}]`;
let config = event.config;
console.log(invokeId, "starting execution");
// get by api or parse it out from query
if (!config) {
@ -87,17 +90,17 @@ exports.handler = async function(context, event, callback) {
if (!discordLock) {
discordLock = true;
console.log(
"UnlockPromise: I was the fastest, so I will attempt to notify discord users before resolving with unlock"
invokeId, "UnlockPromise: I was the fastest, so I will attempt to notify discord users before resolving with unlock"
);
await notifyAllDiscord(context, config, `🔓 Doorman buzzed someone up @ Door "${config.door}"`, JSON.stringify(body.fingerprint));
resolve(twiml);
} else {
console.log(
"UnlockPromise: dropping out of the race, graceful fallback is already notifiying discord users"
invokeId, "UnlockPromise: dropping out of the race, graceful fallback is already notifiying discord users"
);
}
}
}).catch(err => console.log(err));
}).catch(err => console.log(invokeId, err));
}, 500));
});
@ -110,7 +113,7 @@ exports.handler = async function(context, event, callback) {
discordLock = true;
console.log(
"GracefulFallbackPromise: I was the fastest, so I will attempt to notify discord users before resolving with a call"
invokeId, "GracefulFallbackPromise: I was the fastest, so I will attempt to notify discord users before resolving with a call"
);
await notifyAllDiscord(
context,
@ -120,7 +123,7 @@ exports.handler = async function(context, event, callback) {
resolve(twiml);
} else {
console.log(
"GracefulFallbackPromise: dropping out of the race, unlock is already notifying discord users"
invokeId, "GracefulFallbackPromise: dropping out of the race, unlock is already notifying discord users"
);
}
}, 6000));
@ -131,15 +134,15 @@ exports.handler = async function(context, event, callback) {
const twiml = new Twilio.twiml.VoiceResponse();
dialFallbackTwiml(twiml, config);
console.error(
"UngracefulFallbackPromise: Cutting it too close to timeout! Skipping notifying users and calling fallback"
invokeId, "UngracefulFallbackPromise: Cutting it too close to timeout! Skipping notifying users and calling fallback"
);
resolve(twiml);
}, 8000));
});
const twiml = await Promise.race([unlockPromise, gracefulFallbackPromise, ungracefulFallbackPromise]);
console.log("Race ended, clearing residual timers");
timeouts.forEach(timeout => clearTimeout(timeout));
intervals.forEach(interval => clearInterval(interval));
console.log(invokeId, "Race ended, clearing residual timers");
// timeouts.forEach(timeout => clearTimeout(timeout));
// intervals.forEach(interval => clearInterval(interval));
callback(null, twiml);
};