Skip to content

Commit

Permalink
Add retries to updateStats
Browse files Browse the repository at this point in the history
  • Loading branch information
Inkvi committed Apr 25, 2024
1 parent 7f31fb9 commit eed50bf
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions src/stats.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Context } from "@/generated";
import retry from "async-retry";
import { defaultRetryOpts } from "./retry";

export enum StatName {
SendPackets = 'SendPackets',
Expand All @@ -15,15 +17,18 @@ export enum StatName {
}

export async function updateStats(context: Context, id: StatName) {
await context.db.Stat.upsert({
id: id,
create: {
val: 1,
},
update: ({current}) => {
return {
val: current.val + 1
}
}
});
await retry(async bail => {
await context.db.Stat.upsert({
id: id,
create: {
val: 1,
},
update: ({current}) => {
return {
val: current.val + 1
}
}
});
}, defaultRetryOpts
)
}

0 comments on commit eed50bf

Please sign in to comment.