Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Sync partner search for deleted enrollments when the cleanup fails

Rafi434048bb64e8
diff --git a/apps/web/scripts/partners/find-orphaned-program-enrollments.ts b/apps/web/scripts/partners/find-orphaned-program-enrollments.ts
index 263ce0e828..f795b3e223 100644
--- a/apps/web/scripts/partners/find-orphaned-program-enrollments.ts
+++ b/apps/web/scripts/partners/find-orphaned-program-enrollments.ts
@@ -78,22 +78,25 @@ async function main() {
return;
}
- let deletedCount = 0;
+ const deletedEnrollmentIds: string[] = [];
+
+ try {
+ // one enrollment at a time, since bulkDeleteLinks expects links from a single workspace
+ for (const programEnrollment of orphanedProgramEnrollments) {
+ await deleteOrphanedProgramEnrollment(programEnrollment);
+ deletedEnrollmentIds.push(programEnrollment.id);
+ }
+ } finally {
+ // the sync job removes enrollments it cannot read back from the search index.
+ // Runs on failure too, so enrollments deleted before the error are synced.
+ await queuePartnerSearchSync({
+ enrollmentIds: deletedEnrollmentIds,
+ });
- // one enrollment at a time, since bulkDeleteLinks expects links from a single workspace
- for (const programEnrollment of orphanedProgramEnrollments) {
- await deleteOrphanedProgramEnrollment(programEnrollment);
- deletedCount++;
+ console.log(
+ `Deleted ${deletedEnrollmentIds.length} of ${orphanedProgramEnrollments.length} orphaned program enrollments.`,
+ );
}
-
- // the sync job removes enrollments it cannot read back from the search index
- await queuePartnerSearchSync({
- enrollmentIds: orphanedProgramEnrollments.map(({ id }) => id),
- });
-
- console.log(
- `Deleted ${deletedCount} of ${orphanedProgramEnrollments.length} orphaned program enrollments.`,
- );
}
async function deleteOrphanedProgramEnrollment({