diff --git a/src/stats.ts b/src/stats.ts index 2f20e12..6c59db9 100644 --- a/src/stats.ts +++ b/src/stats.ts @@ -1,4 +1,6 @@ import { Context } from "@/generated"; +import retry from "async-retry"; +import { defaultRetryOpts } from "./retry"; export enum StatName { SendPackets = 'SendPackets', @@ -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 + ) } \ No newline at end of file