Skip to content

Commit

Permalink
increase function timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
OronNadiv committed Sep 4, 2024
1 parent 6e3817b commit 6459fd9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
3 changes: 2 additions & 1 deletion functions/src/auth2Users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ const gravatar = require('gravatar')


export interface Auth2UsersOptions {
syncGravatar: boolean
syncGravatar: boolean,
user?: UserRecord
}

const Auth2Users = (admin: Admin.app.App) => {
Expand Down
28 changes: 19 additions & 9 deletions functions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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)')
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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())

0 comments on commit 6459fd9

Please sign in to comment.