chore: prevent scheduled job duplicates

This commit is contained in:
Chris Anderson 2025-07-23 09:58:19 -05:00
parent 858c3a894a
commit 1c7a2f0166
4 changed files with 10 additions and 2 deletions

View file

@ -6,6 +6,10 @@ import CampaignEnqueueSendsJob from './CampaignEnqueueSendsJob'
export default class ProcessCampaignsJob extends Job {
static $name = 'process_campaigns_job'
static from(): ProcessCampaignsJob {
return new this().deduplicationKey(this.$name)
}
static async handler() {
const campaigns = await Campaign.query()

View file

@ -14,7 +14,7 @@ export default class ListStatsJob extends Job {
listId: number,
projectId: number,
): ListStatsJob {
return new this({ listId, projectId })
return new this({ listId, projectId }).deduplicationKey(`${this.name}_${listId}`)
}
static async handler({ listId, projectId }: ListStatsParams) {

View file

@ -5,6 +5,10 @@ import ListStatsJob from './ListStatsJob'
export default class ProcessListsJob extends Job {
static $name = 'process_lists_job'
static from(): ProcessListsJob {
return new this().deduplicationKey(this.$name)
}
static async handler() {
const lists = await List.all(qb => qb.whereNot('state', 'loading').whereNull('deleted_at'))

View file

@ -66,7 +66,7 @@ export default class Job implements EncodedJob {
return this.$static.handler(this.data, this)
}
constructor(data: any) {
constructor(data: any = {}) {
this.data = data
}