feat: handle determining delay and when to send at notification processing instead of managing scheduledAt. this removes the need for scheduledAt as we will do the scheduling calculations at processing time

GitOrigin-RevId: d0bbd5adc29ab58a797c171b55aabfda1cec39ea
This commit is contained in:
Jimmy Domagala-Tang
2025-10-23 10:04:02 -04:00
committed by Copybot
parent 23fc714d93
commit bfa70bf43b
2 changed files with 50 additions and 2 deletions

View File

@@ -0,0 +1,44 @@
/* eslint-disable no-unused-vars */
import Helpers from './lib/helpers.mjs'
import { getCollectionInternal } from './lib/mongodb.mjs'
const tags = ['server-pro', 'saas']
const oldIndexes = [
{
key: {
scheduledAt: 1,
},
name: 'scheduledAt_1',
expireAfterSeconds: 60 * 60 * 24, // expire after 24 hours
},
]
const newIndexes = [
{
key: {
createdAt: 1,
},
name: 'createdAt_1',
expireAfterSeconds: 60 * 60 * 24, // expire after 24 hours
},
]
const migrate = async client => {
const emailNotifications = await getCollectionInternal('emailNotifications')
await Helpers.dropIndexesFromCollection(emailNotifications, oldIndexes)
await Helpers.addIndexesToCollection(emailNotifications, newIndexes)
}
const rollback = async client => {
const emailNotifications = await getCollectionInternal('emailNotifications')
await Helpers.dropIndexesFromCollection(emailNotifications, newIndexes)
await Helpers.addIndexesToCollection(emailNotifications, oldIndexes)
}
export default {
tags,
migrate,
rollback,
}