Skip to content

Commit

Permalink
Don't error our device saving for nonexistent user (#587)
Browse files Browse the repository at this point in the history
  • Loading branch information
pushchris authored Dec 20, 2024
1 parent 22a6991 commit 7721d4c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
9 changes: 9 additions & 0 deletions apps/platform/src/queue/Job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -29,6 +34,10 @@ export default class Job implements EncodedJob {
attempts: 3,
}

state: JobState = {
attemptsMade: 0,
}

static $name: string = Job.constructor.name

get name() {
Expand Down
3 changes: 3 additions & 0 deletions apps/platform/src/queue/RedisQueueProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ export default class RedisQueueProvider implements QueueProvider {
...job.data.options,
jobId: job.id,
},
state: {
attemptsMade: job.attemptsMade,
},
token,
})
}, {
Expand Down
11 changes: 9 additions & 2 deletions apps/platform/src/users/UserDeviceJob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

0 comments on commit 7721d4c

Please sign in to comment.