From fc8aca7dd0d01dcf3795044cf32ed588597cdfe6 Mon Sep 17 00:00:00 2001 From: Bing Wen Tan Date: Tue, 7 Nov 2023 13:13:07 +0800 Subject: [PATCH 1/2] switched batch jobs to v2 --- .../src/definitions/batchJobs/batchJobs.ts | 43 +++++++++++-------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/functions/src/definitions/batchJobs/batchJobs.ts b/functions/src/definitions/batchJobs/batchJobs.ts index 27077fd7..d7ae8277 100644 --- a/functions/src/definitions/batchJobs/batchJobs.ts +++ b/functions/src/definitions/batchJobs/batchJobs.ts @@ -9,6 +9,7 @@ import { Timestamp } from "firebase-admin/firestore" import { getCount } from "../common/counters" import { getThresholds } from "../common/utils" import { defineString } from "firebase-functions/params" +import { onSchedule } from "firebase-functions/v2/scheduler" const runtimeEnvironment = defineString("ENVIRONMENT") @@ -125,28 +126,32 @@ async function interimPromptHandler() { } } -const checkSessionExpiring = functions - .region("asia-southeast1") - .runWith({ secrets: ["WHATSAPP_USER_BOT_PHONE_NUMBER_ID", "WHATSAPP_TOKEN"] }) - .pubsub.schedule("1 * * * *") - .timeZone("Asia/Singapore") - .onRun(checkConversationSessionExpiring) +const checkSessionExpiring = onSchedule( + { + schedule: "1 * * * *", + timeZone: "Asia/Singapore", + secrets: ["WHATSAPP_USER_BOT_PHONE_NUMBER_ID", "WHATSAPP_TOKEN"], + }, + deactivateAndRemind +) -const scheduledDeactivation = functions - .region("asia-southeast1") - .runWith({ +const scheduledDeactivation = onSchedule( + { + schedule: "11 20 * * *", + timeZone: "Asia/Singapore", secrets: ["WHATSAPP_CHECKERS_BOT_PHONE_NUMBER_ID", "WHATSAPP_TOKEN"], - }) - .pubsub.schedule("11 20 * * *") - .timeZone("Asia/Singapore") - .onRun(deactivateAndRemind) + }, + deactivateAndRemind +) -const sendInterimPrompt = functions - .region("asia-southeast1") - .runWith({ secrets: ["WHATSAPP_USER_BOT_PHONE_NUMBER_ID", "WHATSAPP_TOKEN"] }) - .pubsub.schedule("*/20 * * * *") - .timeZone("Asia/Singapore") - .onRun(interimPromptHandler) +const sendInterimPrompt = onSchedule( + { + schedule: "2,22,42 * * * *", + timeZone: "Asia/Singapore", + secrets: ["WHATSAPP_USER_BOT_PHONE_NUMBER_ID", "WHATSAPP_TOKEN"], + }, + interimPromptHandler +) export { checkSessionExpiring, From 34c785c1ca71d42484d13d1ee2df6f22bac1b8ad Mon Sep 17 00:00:00 2001 From: Bing Wen Tan Date: Tue, 7 Nov 2023 13:16:41 +0800 Subject: [PATCH 2/2] Fixed mistake with session expiring batch job --- functions/src/definitions/batchJobs/batchJobs.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/src/definitions/batchJobs/batchJobs.ts b/functions/src/definitions/batchJobs/batchJobs.ts index d7ae8277..6347d8da 100644 --- a/functions/src/definitions/batchJobs/batchJobs.ts +++ b/functions/src/definitions/batchJobs/batchJobs.ts @@ -132,7 +132,7 @@ const checkSessionExpiring = onSchedule( timeZone: "Asia/Singapore", secrets: ["WHATSAPP_USER_BOT_PHONE_NUMBER_ID", "WHATSAPP_TOKEN"], }, - deactivateAndRemind + checkConversationSessionExpiring ) const scheduledDeactivation = onSchedule(