Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}
}
Loading