refactor: platform billing jobs tasks constants (#27190)

This commit is contained in:
Morgan authored and GitHub committed 2026-01-23 12:54:05 +00:00
1 parent 4115eaacbd
commit b9b7e50f5a
9 files changed
+35 -12

No files matched your search

@@ -0,0 +1,9 @@
export const INCREMENT_USAGE_JOB_ID = "platform.billing.increment-usage";
export const RESCHEDULE_USAGE_INCREMENT_JOB_ID = "platform.billing.reschedule-usage-increment";
export const CANCEL_USAGE_INCREMENT_JOB_ID = "platform.billing.cancel-usage-increment";
const INCREMENT_USAGE_JOB_TAG = "platform.billing.usage.";
export const getIncrementUsageJobTag = (bookingUid: string): string =>
`${INCREMENT_USAGE_JOB_TAG}${bookingUid}`;
const INCREMENT_USAGE_IDEMPOTENCY_KEY = `platform.billing.usage.`;
export const getIncrementUsageIdempotencyKey = (bookingUid: string, userId: number): string =>
`${INCREMENT_USAGE_IDEMPOTENCY_KEY}${bookingUid}-${userId}`;
@@ -1,11 +1,9 @@
import { logger, runs, schemaTask, type TaskWithSchema } from "@trigger.dev/sdk";
import type { z } from "zod";
import { CANCEL_USAGE_INCREMENT_JOB_ID, getIncrementUsageJobTag } from "../constants";
import { platformBillingTaskConfig } from "./config";
import { platformBillingCancelUsageIncrementTaskSchema } from "./schema";
export const CANCEL_USAGE_INCREMENT_JOB_ID = "platform.billing.cancel-usage-increment";
export const cancelUsageIncrement: TaskWithSchema<
typeof CANCEL_USAGE_INCREMENT_JOB_ID,
typeof platformBillingCancelUsageIncrementTaskSchema
@@ -16,7 +14,7 @@ export const cancelUsageIncrement: TaskWithSchema<
run: async (payload: z.infer<typeof platformBillingCancelUsageIncrementTaskSchema>) => {
const runId: string = (
await runs.list({
tag: `increment-${payload.bookingUid}`,
tag: getIncrementUsageJobTag(payload.bookingUid),
limit: 1,
})
)?.data?.[0]?.id;
@@ -1,11 +1,10 @@
import { ErrorWithCode } from "@calcom/lib/errors";
import { logger, schemaTask, type TaskWithSchema } from "@trigger.dev/sdk";
import type { z } from "zod";
import { INCREMENT_USAGE_JOB_ID } from "../constants";
import { platformBillingTaskConfig } from "./config";
import { platformBillingTaskSchema } from "./schema";
export const INCREMENT_USAGE_JOB_ID = "platform.billing.increment-usage";
export const incrementUsage: TaskWithSchema<typeof INCREMENT_USAGE_JOB_ID, typeof platformBillingTaskSchema> =
schemaTask({
id: INCREMENT_USAGE_JOB_ID,
@@ -1,10 +1,9 @@
import { logger, runs, schemaTask, type TaskWithSchema } from "@trigger.dev/sdk";
import type z from "zod";
import { getIncrementUsageJobTag, RESCHEDULE_USAGE_INCREMENT_JOB_ID } from "../constants";
import { platformBillingTaskConfig } from "./config";
import { platformBillingRescheduleUsageIncrementTaskSchema } from "./schema";
export const RESCHEDULE_USAGE_INCREMENT_JOB_ID = "platform.billing.reschedule-usage-increment";
export const rescheduleUsageIncrement: TaskWithSchema<
typeof RESCHEDULE_USAGE_INCREMENT_JOB_ID,
typeof platformBillingRescheduleUsageIncrementTaskSchema
@@ -15,7 +14,7 @@ export const rescheduleUsageIncrement: TaskWithSchema<
run: async (payload: z.infer<typeof platformBillingRescheduleUsageIncrementTaskSchema>) => {
const runId: string = (
await runs.list({
tag: `platform.billing.usage.${payload.bookingUid}`,
tag: getIncrementUsageJobTag(payload.bookingUid),
limit: 1,
})
)?.data?.[0]?.id;