Don't error our device saving for nonexistent user (#587)

This commit is contained in:
Chris Anderson 2024-12-19 21:23:20 -06:00 committed by GitHub
parent 22a6991bb2
commit 7721d4c010
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 21 additions and 2 deletions

View file

@ -6,9 +6,14 @@ interface JobOptions {
jobId?: string
}
interface JobState {
attemptsMade: number
}
export interface EncodedJob {
data: any
options: JobOptions
state: JobState
name: string
token?: string
}
@ -29,6 +34,10 @@ export default class Job implements EncodedJob {
attempts: 3,
}
state: JobState = {
attemptsMade: 0,
}
static $name: string = Job.constructor.name
get name() {

View file

@ -95,6 +95,9 @@ export default class RedisQueueProvider implements QueueProvider {
...job.data.options,
jobId: job.id,
},
state: {
attemptsMade: job.attemptsMade,
},
token,
})
}, {

View file

@ -13,7 +13,14 @@ export default class UserDeviceJob extends Job {
return new this(data)
}
static async handler({ project_id, ...device }: UserDeviceTrigger) {
await saveDevice(project_id, device)
static async handler({ project_id, ...device }: UserDeviceTrigger, job: UserDeviceJob) {
const attempts = job.options.attempts ?? 1
const attemptsMade = job.state.attemptsMade ?? 0
try {
await saveDevice(project_id, device)
} catch (error) {
if (attemptsMade < (attempts - 1)) throw error
}
}
}