add polling lock, and reduce inner handler timeout
This commit is contained in:
parent
55c5d59b04
commit
97956e376e
@ -64,7 +64,7 @@ const FALLBACK_CALLBACK: CallbackResult = [null, REJECT_RESPONSE];
|
|||||||
|
|
||||||
const MINIMUM_MS_TO_SEND_RESPONSE: number = 250;
|
const MINIMUM_MS_TO_SEND_RESPONSE: number = 250;
|
||||||
const FUNCTION_MAXIMUM_DURATION_MS: number = 10_000;
|
const FUNCTION_MAXIMUM_DURATION_MS: number = 10_000;
|
||||||
const INNER_HANDLER_MAXIMUM_DURATION_MS: number = 9_000;
|
const INNER_HANDLER_MAXIMUM_DURATION_MS: number = 8_750;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A decorator for twilio handlers. It provides a metrics registry and
|
* A decorator for twilio handlers. It provides a metrics registry and
|
||||||
|
|||||||
@ -78,6 +78,8 @@ export const handler: ServerlessFunctionSignature<TwilioContext, BuzzerDialEvent
|
|||||||
let intervals: Timer[] = [];
|
let intervals: Timer[] = [];
|
||||||
let timeouts: Timer[] = [];
|
let timeouts: Timer[] = [];
|
||||||
|
|
||||||
|
let pollLock = false;
|
||||||
|
|
||||||
const unlockPromise = new Promise<VoiceResponse>((resolve, reject) => {
|
const unlockPromise = new Promise<VoiceResponse>((resolve, reject) => {
|
||||||
intervals.push(setInterval(() => {
|
intervals.push(setInterval(() => {
|
||||||
getMetricFromRegistry<Counter>(metricsRegistry, BuzzerActivatedMetrics.POLL_ATTEMPTS)
|
getMetricFromRegistry<Counter>(metricsRegistry, BuzzerActivatedMetrics.POLL_ATTEMPTS)
|
||||||
@ -86,12 +88,20 @@ export const handler: ServerlessFunctionSignature<TwilioContext, BuzzerDialEvent
|
|||||||
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;
|
||||||
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) {
|
if (body?.status === DoorStatus.OPEN) {
|
||||||
|
pollLock = false;
|
||||||
clearInterval(intervals[0]);
|
clearInterval(intervals[0]);
|
||||||
const twiml = doorOpenTwiml(config);
|
const twiml = doorOpenTwiml(config);
|
||||||
|
|
||||||
@ -112,7 +122,7 @@ export const handler: ServerlessFunctionSignature<TwilioContext, BuzzerDialEvent
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).catch(err => console.log(invokeId + err));
|
}).catch(err => console.log(invokeId + err));
|
||||||
}, 1250));
|
}, 400));
|
||||||
});
|
});
|
||||||
|
|
||||||
const gracefulFallbackPromise = new Promise<VoiceResponse>((resolve, reject) => {
|
const gracefulFallbackPromise = new Promise<VoiceResponse>((resolve, reject) => {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user