From 6459fd94191a54f2eb212ab1e0b892e178ebc236 Mon Sep 17 00:00:00 2001 From: Oron Nadiv Date: Tue, 3 Sep 2024 22:54:10 -0700 Subject: [PATCH] increase function timeout --- functions/src/auth2Users.ts | 3 ++- functions/src/index.ts | 28 +++++++++++++++++++--------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/functions/src/auth2Users.ts b/functions/src/auth2Users.ts index 05fd5e5..31ab0b8 100755 --- a/functions/src/auth2Users.ts +++ b/functions/src/auth2Users.ts @@ -10,7 +10,8 @@ const gravatar = require('gravatar') export interface Auth2UsersOptions { - syncGravatar: boolean + syncGravatar: boolean, + user?: UserRecord } const Auth2Users = (admin: Admin.app.App) => { diff --git a/functions/src/index.ts b/functions/src/index.ts index 96c35a1..4fd6d8d 100644 --- a/functions/src/index.ts +++ b/functions/src/index.ts @@ -11,6 +11,7 @@ import UpdateEvents from './updateEvents' import Users2Contacts from './users2Contacts' import * as functions from 'firebase-functions' import { info, error } from "firebase-functions/logger" +import { UserRecord } from 'firebase-functions/lib/providers/auth' import * as Admin from 'firebase-admin' import { EMAIL } from './fields' import { props } from 'bluebird' @@ -40,9 +41,9 @@ const stripeImpl = Stripe(admin, { const users2Contacts = Users2Contacts(admin) const updateEvents = UpdateEvents(admin, app_id, city_id) -const AUTH_2_USERS_TIMEOUT_IN_SECONDS = 180 +const ITERATION_ON_ACCOUNTS_TIMEOUT_IN_SECONDS = 180 -const auth2UsersExec = (options: Auth2UsersOptions) => async () => { +const auth2UsersExec = async (options: Auth2UsersOptions) => { try { await auth2Users(options) info('Calling process.exit(0)') @@ -58,20 +59,27 @@ const auth2UsersExec = (options: Auth2UsersOptions) => async () => { } } -export const purgeUsersUnder13CronJob = functions.pubsub +export const purgeUsersUnder13CronJob = functions + .runWith({ timeoutSeconds: ITERATION_ON_ACCOUNTS_TIMEOUT_IN_SECONDS }) + .pubsub .schedule('10 */6 * * *') .onRun(async () => await purgeUsersUnder13()) + export const auth2UsersCronJob = functions - .runWith({ timeoutSeconds: AUTH_2_USERS_TIMEOUT_IN_SECONDS }) + .runWith({ timeoutSeconds: ITERATION_ON_ACCOUNTS_TIMEOUT_IN_SECONDS }) .pubsub .schedule('20 */6 * * *') .onRun(async () => await auth2UsersExec({ syncGravatar: true })) + export const auth2UsersOnCreate = functions - .runWith({ timeoutSeconds: AUTH_2_USERS_TIMEOUT_IN_SECONDS }) + .runWith({ timeoutSeconds: ITERATION_ON_ACCOUNTS_TIMEOUT_IN_SECONDS }) .auth - .user().onCreate(auth2UsersExec({ syncGravatar: false })) + .user() + .onCreate(async (user: UserRecord) => await auth2UsersExec({ syncGravatar: false, user })) -export const users2ContactsCronJob = functions.pubsub +export const users2ContactsCronJob = functions + .runWith({ timeoutSeconds: ITERATION_ON_ACCOUNTS_TIMEOUT_IN_SECONDS }) + .pubsub .schedule('30 */6 * * *') .onRun(async () => { try { @@ -83,7 +91,7 @@ export const users2ContactsCronJob = functions.pubsub }) export const contacts2MailChimpCronJob = functions - .runWith({ timeoutSeconds: 180 }) + .runWith({ timeoutSeconds: ITERATION_ON_ACCOUNTS_TIMEOUT_IN_SECONDS }) .pubsub.schedule('40 */6 * * *') .onRun(async () => { try { @@ -182,6 +190,8 @@ export const deleteUser = functions await deleteUserImpl({ uid: targetUID, email: targetEmail }) }) -export const sendMembershipRemindersCronJob = functions.pubsub +export const sendMembershipRemindersCronJob = functions + .runWith({ timeoutSeconds: ITERATION_ON_ACCOUNTS_TIMEOUT_IN_SECONDS }) + .pubsub .schedule('0 19 * * *') .onRun(async () => await sendMembershipReminders())