fix poll lock + metrics
All checks were successful
Build and push image for doorman-homeassistant / diff (push) Successful in 11s
Build and push Doorman UI / API / diff (push) Successful in 11s
Build and push image for doorman-homeassistant / docker (push) Has been skipped
Build and push image for doorman-homeassistant / deploy-gitainer (push) Has been skipped
Build and push Doorman UI / API / twilio (push) Successful in 2m49s
All checks were successful
Build and push image for doorman-homeassistant / diff (push) Successful in 11s
Build and push Doorman UI / API / diff (push) Successful in 11s
Build and push image for doorman-homeassistant / docker (push) Has been skipped
Build and push image for doorman-homeassistant / deploy-gitainer (push) Has been skipped
Build and push Doorman UI / API / twilio (push) Successful in 2m49s
This commit is contained in:
parent
8aa1fa7b08
commit
09231cd7f7
@ -87,25 +87,26 @@ export const handler: ServerlessFunctionSignature<TwilioContext, BuzzerDialEvent
|
|||||||
|
|
||||||
const unlockPromise = new Promise<VoiceResponse>((resolve, reject) => {
|
const unlockPromise = new Promise<VoiceResponse>((resolve, reject) => {
|
||||||
intervals.push(setInterval(() => {
|
intervals.push(setInterval(() => {
|
||||||
|
// prevent multiple polling at once
|
||||||
|
if (pollLock) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
getMetricFromRegistry<Counter>(metricsRegistry, BuzzerActivatedMetrics.POLL_ATTEMPTS)
|
getMetricFromRegistry<Counter>(metricsRegistry, BuzzerActivatedMetrics.POLL_ATTEMPTS)
|
||||||
.inc({ door: config.door }, 1);
|
.inc({ door: config.door }, 1);
|
||||||
|
|
||||||
const recordPollLatency = getMetricFromRegistry<Summary>(metricsRegistry, BuzzerActivatedMetrics.POLL_LATENCY)
|
const recordPollLatency = getMetricFromRegistry<Summary>(metricsRegistry, BuzzerActivatedMetrics.POLL_LATENCY)
|
||||||
.startTimer({ door: config.door });
|
.startTimer({ door: config.door });
|
||||||
|
|
||||||
// prevent multiple polling at once
|
|
||||||
if (pollLock) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
pollLock = true;
|
pollLock = true;
|
||||||
fetch(context.DOORMAN_URL + `/api/door/status?door=${config.door}`)
|
fetch(context.DOORMAN_URL + `/api/door/status?door=${config.door}`)
|
||||||
.then(res => res.json())
|
.then(res => res.json())
|
||||||
.then(async (rawBody) => {
|
.then(async (rawBody) => {
|
||||||
let body = rawBody as StatusResponse;
|
let body = rawBody as StatusResponse;
|
||||||
recordPollLatency();
|
recordPollLatency();
|
||||||
if (body?.status === DoorStatus.OPEN) {
|
|
||||||
pollLock = false;
|
pollLock = false;
|
||||||
|
|
||||||
|
if (body?.status === DoorStatus.OPEN) {
|
||||||
clearInterval(intervals[0]);
|
clearInterval(intervals[0]);
|
||||||
const twiml = doorOpenTwiml(config);
|
const twiml = doorOpenTwiml(config);
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user