mirror of
https://fast.feibisi.com/https://github.com/parcelvoy/platform.git
synced 2025-08-28 11:46:02 +08:00
Don't error our device saving for nonexistent user (#587)
This commit is contained in:
parent
22a6991bb2
commit
7721d4c010
3 changed files with 21 additions and 2 deletions
|
@ -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() {
|
||||
|
|
|
@ -95,6 +95,9 @@ export default class RedisQueueProvider implements QueueProvider {
|
|||
...job.data.options,
|
||||
jobId: job.id,
|
||||
},
|
||||
state: {
|
||||
attemptsMade: job.attemptsMade,
|
||||
},
|
||||
token,
|
||||
})
|
||||
}, {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue