refactor: platform billing jobs tasks constants (#27190)
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { getIncrementUsageIdempotencyKey, getIncrementUsageJobTag } from "@calcom/platform-libraries/tasker";
|
||||
import { InjectQueue } from "@nestjs/bull";
|
||||
import {
|
||||
BadRequestException,
|
||||
@@ -453,8 +454,8 @@ export class BillingService implements IBillingService, OnModuleDestroy {
|
||||
payload: { userId },
|
||||
options: {
|
||||
delay: startTime,
|
||||
tags: [`platform.billing.usage.${uid}`],
|
||||
idempotencyKey: `platform.billing.usage.${uid}-${userId}`,
|
||||
tags: [getIncrementUsageJobTag(uid)],
|
||||
idempotencyKey: getIncrementUsageIdempotencyKey(uid, userId),
|
||||
},
|
||||
});
|
||||
return true;
|
||||
|
||||
@@ -33,7 +33,8 @@
|
||||
"@calcom/platform-libraries/private-links": ["../../../packages/platform/libraries/private-links.ts"],
|
||||
"@calcom/platform-libraries/organizations": ["../../../packages/platform/libraries/organizations.ts"],
|
||||
"@calcom/platform-libraries/errors": ["../../../packages/platform/libraries/errors.ts"],
|
||||
"@calcom/platform-libraries/calendars": ["../../../packages/platform/libraries/calendars.ts"]
|
||||
"@calcom/platform-libraries/calendars": ["../../../packages/platform/libraries/calendars.ts"],
|
||||
"@calcom/platform-libraries/tasker": ["../../../packages/platform/libraries/tasker.ts"]
|
||||
},
|
||||
"incremental": true,
|
||||
"skipLibCheck": true,
|
||||
|
||||
@@ -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}`;
|
||||
+2
-4
@@ -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,
|
||||
|
||||
+2
-3
@@ -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;
|
||||
|
||||
@@ -109,6 +109,11 @@
|
||||
"import": "./dist/calendars.js",
|
||||
"require": "./dist/calendars.cjs",
|
||||
"types": "./dist/calendars.d.ts"
|
||||
},
|
||||
"./tasker": {
|
||||
"import": "./dist/tasker.js",
|
||||
"require": "./dist/tasker.cjs",
|
||||
"types": "./dist/tasker.d.ts"
|
||||
}
|
||||
},
|
||||
"typesVersions": {
|
||||
@@ -154,6 +159,9 @@
|
||||
],
|
||||
"calendars": [
|
||||
"dist/calendars.d.ts"
|
||||
],
|
||||
"tasker": [
|
||||
"dist/tasker.d.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
export {
|
||||
CANCEL_USAGE_INCREMENT_JOB_ID,
|
||||
getIncrementUsageIdempotencyKey,
|
||||
getIncrementUsageJobTag,
|
||||
INCREMENT_USAGE_JOB_ID,
|
||||
RESCHEDULE_USAGE_INCREMENT_JOB_ID,
|
||||
} from "@calcom/features/ee/organizations/lib/billing/tasker/constants";
|
||||
@@ -44,6 +44,7 @@ export default defineConfig({
|
||||
pbac: resolve(__dirname, "./pbac.ts"),
|
||||
errors: resolve(__dirname, "./errors.ts"),
|
||||
calendars: resolve(__dirname, "./calendars.ts"),
|
||||
tasker: resolve(__dirname, "./tasker.ts"),
|
||||
},
|
||||
name: "calcom-lib",
|
||||
fileName: "calcom-lib",
|
||||
|
||||
Reference in New Issue
Block a user