File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 )
Original file line number Diff line number Diff line change 11{
2- "version" : " 0.5.7 " ,
2+ "version" : " 0.5.8 " ,
33 "name" : " letterspace" ,
44 "private" : true ,
55 "scripts" : {
You can’t perform that action at this time.
0 commit comments