implement best efforts cleanup
This commit is contained in:
parent
29786f5780
commit
1bca8cf9dc
@ -12,6 +12,7 @@ import { z } from "zod";
|
||||
import { UserAgentHeader } from "../../../utils/blockUserAgent";
|
||||
import { setResponseJson } from "../../../utils/responseUtils";
|
||||
import { LOG_CALL_SK, LogCallSchema } from "../../../schema/LogCall";
|
||||
import { isTTLInFuture } from "../../../common/TTLHelper";
|
||||
|
||||
export const LogCallRequestSchema = z.object({
|
||||
caller: z.string(),
|
||||
@ -46,6 +47,15 @@ export const handler: ServerlessFunctionSignature<TwilioContext, LogCallRequestT
|
||||
msg: "Onboarding is not open",
|
||||
});
|
||||
} else {
|
||||
// best efforts cleanup
|
||||
// TODO: make this use an INDEX instead of scan
|
||||
console.log("Attempting best efforts cleanup of logged calls")
|
||||
const logs = await db.entities.logCall.findAll();
|
||||
const toRemove = logs.filter(log => !isTTLInFuture(log));
|
||||
console.log(`There are ${toRemove.length} old call logs to remove`);
|
||||
await db.entities.logCall.deleteBatch(toRemove);
|
||||
console.log("done cleaning up logged calls");
|
||||
|
||||
// log this caller
|
||||
const otp = getCode();
|
||||
const logCall = LogCallSchema.parse({
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user