Skip to content

Commit 1f48c14

Browse files
committed
Bug Fix
1 parent fe84247 commit 1f48c14

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

apps/backend/src/cron/processQueuedCampaigns.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,24 @@ export const processQueuedCampaigns = cronJob(
229229
data: messagesToCreate,
230230
})
231231

232-
await tx.campaign.update({
233-
where: { id: campaign.id },
234-
data: { status: "SENDING" },
232+
const subscribersLeft = await tx.subscriber.count({
233+
where: {
234+
Messages: { none: { campaignId: campaign.id } },
235+
ListSubscribers: {
236+
some: {
237+
unsubscribedAt: null,
238+
},
239+
},
240+
},
235241
})
236242

243+
if (subscribersLeft === 0) {
244+
await tx.campaign.update({
245+
where: { id: campaign.id },
246+
data: { status: "SENDING" },
247+
})
248+
}
249+
237250
console.log(
238251
`Cron job: Created ${messagesToCreate.length} messages for campaign ${campaign.id}.`
239252
)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "0.5.7",
2+
"version": "0.5.8",
33
"name": "letterspace",
44
"private": true,
55
"scripts": {

0 commit comments

Comments
 (0)