Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix: add race condition check to billing queue (#5074)

Max Deichmannbc8923485e60
diff --git a/worker/src/ee/cloudUsageMetering/handleCloudUsageMeteringJob.ts b/worker/src/ee/cloudUsageMetering/handleCloudUsageMeteringJob.ts
index 4f679a48ca..ccd4bb6958 100644
--- a/worker/src/ee/cloudUsageMetering/handleCloudUsageMeteringJob.ts
+++ b/worker/src/ee/cloudUsageMetering/handleCloudUsageMeteringJob.ts
@@ -70,15 +70,27 @@ export const handleCloudUsageMeteringJob = async (job: Job) => {
}
}
- await prisma.cronJobs.update({
- where: {
- name: cloudUsageMeteringDbCronJobName,
- },
- data: {
- state: CloudUsageMeteringDbCronJobStates.Processing,
- jobStartedAt: new Date(),
- },
- });
+ try {
+ await prisma.cronJobs.update({
+ where: {
+ name: cloudUsageMeteringDbCronJobName,
+ state: cron.state,
+ jobStartedAt: cron.jobStartedAt,
+ },
+ data: {
+ state: CloudUsageMeteringDbCronJobStates.Processing,
+ jobStartedAt: new Date(),
+ },
+ });
+ } catch (e) {
+ logger.warn(
+ "[CLOUD USAGE METERING] Failed to update cron job state, potential race condition, exiting",
+ {
+ e,
+ },
+ );
+ return;
+ }
// timing
const meterIntervalStart = cron.lastRun;