chore: reduce state job processing

This commit is contained in:
Chris Anderson 2025-08-02 08:15:42 -05:00
parent 04a9f3f229
commit 2701aef923

View file

@ -7,6 +7,10 @@ import App from '../app'
export default class CampaignStateJob extends Job {
static $name = 'campaign_state_job'
static from(): CampaignStateJob {
return new this().deduplicationKey(this.$name)
}
static async handler() {
// Fetch anything that is currently running, has finished
@ -18,7 +22,10 @@ export default class CampaignStateJob extends Job {
qb.where('state', 'finished')
.where('send_at', '>', subDays(Date.now(), 2))
})
.orWhereIn('id', openedCampaignIds),
.orWhere(function(qb) {
qb.whereIn('id', openedCampaignIds)
.whereNotIn('state', ['draft', 'aborted'])
}),
)
for (const campaign of campaigns) {