add invokeid and revert residual cleanup
This commit is contained in:
parent
6607b306d0
commit
00491528ee
@ -1,6 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
* Doorman entrypoint
|
* Doorman entrypoint
|
||||||
*/
|
*/
|
||||||
|
const { randomUUID } = require('crypto');
|
||||||
const fetch = require('node-fetch');
|
const fetch = require('node-fetch');
|
||||||
|
|
||||||
async function getConfig(context, buzzer) {
|
async function getConfig(context, buzzer) {
|
||||||
@ -42,7 +43,9 @@ function dialFallbackTwiml(twiml, config) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
exports.handler = async function(context, event, callback) {
|
exports.handler = async function(context, event, callback) {
|
||||||
|
let invokeId = `[${randomUUID()}]`;
|
||||||
let config = event.config;
|
let config = event.config;
|
||||||
|
console.log(invokeId, "starting execution");
|
||||||
|
|
||||||
// get by api or parse it out from query
|
// get by api or parse it out from query
|
||||||
if (!config) {
|
if (!config) {
|
||||||
@ -87,17 +90,17 @@ exports.handler = async function(context, event, callback) {
|
|||||||
if (!discordLock) {
|
if (!discordLock) {
|
||||||
discordLock = true;
|
discordLock = true;
|
||||||
console.log(
|
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));
|
await notifyAllDiscord(context, config, `🔓 Doorman buzzed someone up @ Door "${config.door}"`, JSON.stringify(body.fingerprint));
|
||||||
resolve(twiml);
|
resolve(twiml);
|
||||||
} else {
|
} else {
|
||||||
console.log(
|
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));
|
}, 500));
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -110,7 +113,7 @@ exports.handler = async function(context, event, callback) {
|
|||||||
discordLock = true;
|
discordLock = true;
|
||||||
|
|
||||||
console.log(
|
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(
|
await notifyAllDiscord(
|
||||||
context,
|
context,
|
||||||
@ -120,7 +123,7 @@ exports.handler = async function(context, event, callback) {
|
|||||||
resolve(twiml);
|
resolve(twiml);
|
||||||
} else {
|
} else {
|
||||||
console.log(
|
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));
|
}, 6000));
|
||||||
@ -131,15 +134,15 @@ exports.handler = async function(context, event, callback) {
|
|||||||
const twiml = new Twilio.twiml.VoiceResponse();
|
const twiml = new Twilio.twiml.VoiceResponse();
|
||||||
dialFallbackTwiml(twiml, config);
|
dialFallbackTwiml(twiml, config);
|
||||||
console.error(
|
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);
|
resolve(twiml);
|
||||||
}, 8000));
|
}, 8000));
|
||||||
});
|
});
|
||||||
|
|
||||||
const twiml = await Promise.race([unlockPromise, gracefulFallbackPromise, ungracefulFallbackPromise]);
|
const twiml = await Promise.race([unlockPromise, gracefulFallbackPromise, ungracefulFallbackPromise]);
|
||||||
console.log("Race ended, clearing residual timers");
|
console.log(invokeId, "Race ended, clearing residual timers");
|
||||||
timeouts.forEach(timeout => clearTimeout(timeout));
|
// timeouts.forEach(timeout => clearTimeout(timeout));
|
||||||
intervals.forEach(interval => clearInterval(interval));
|
// intervals.forEach(interval => clearInterval(interval));
|
||||||
callback(null, twiml);
|
callback(null, twiml);
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user