Skip to content

Scheduling infrastructure for absolutely everyone.

fix: platform billing reschedule usage increment via trigger.dev (#27483)

Morgan36e477cebf2d
diff --git a/apps/api/v2/src/modules/billing/services/billing.service.ts b/apps/api/v2/src/modules/billing/services/billing.service.ts
index 1f4540d1d05..7d326c671e0 100644
--- a/apps/api/v2/src/modules/billing/services/billing.service.ts
+++ b/apps/api/v2/src/modules/billing/services/billing.service.ts
@@ -445,8 +445,7 @@ export class BillingService implements IBillingService, OnModuleDestroy {
if (this.configService.get("enableAsyncTasker")) {
if (fromReschedule) {
this.platformBillingTasker.rescheduleUsageIncrement({
- payload: { bookingUid: uid },
- options: { delay: startTime },
+ payload: { bookingUid: uid, rescheduledTime: startTime },
});
return true;
}
diff --git a/packages/features/ee/organizations/lib/billing/tasker/PlatformOrganizationBillingSyncTasker.ts b/packages/features/ee/organizations/lib/billing/tasker/PlatformOrganizationBillingSyncTasker.ts
index 32638981623..c4a72523a52 100644
--- a/packages/features/ee/organizations/lib/billing/tasker/PlatformOrganizationBillingSyncTasker.ts
+++ b/packages/features/ee/organizations/lib/billing/tasker/PlatformOrganizationBillingSyncTasker.ts
@@ -1,6 +1,5 @@
import type { ITaskerDependencies } from "@calcom/lib/tasker/types";
import { nanoid } from "nanoid";
-
import type { PlatformOrganizationBillingTaskService } from "./PlatformOrganizationBillingTaskService";
import type { IPlatformOrganizationBillingTasker } from "./types";
diff --git a/packages/features/ee/organizations/lib/billing/tasker/PlatformOrganizationBillingTasker.ts b/packages/features/ee/organizations/lib/billing/tasker/PlatformOrganizationBillingTasker.ts
index d0401e09311..41fe8945698 100644
--- a/packages/features/ee/organizations/lib/billing/tasker/PlatformOrganizationBillingTasker.ts
+++ b/packages/features/ee/organizations/lib/billing/tasker/PlatformOrganizationBillingTasker.ts
@@ -20,13 +20,13 @@ export class PlatformOrganizationBillingTasker extends Tasker<IPlatformOrganizat
payload: PlatformOrganizationBillingTaskPayload;
options?: TriggerOptions;
}): Promise<{ runId: string }> {
- const { payload } = data;
+ const { payload, options } = data;
let taskResponse: {
runId: string;
} = { runId: "task-not-found" };
try {
- taskResponse = await this.dispatch("incrementUsage", payload, data.options);
+ taskResponse = await this.dispatch("incrementUsage", payload, options);
this.logger.info(`PlatformOrganizationBillingTasker incrementUsage success:`, taskResponse, {
userId: payload.userId,
@@ -41,14 +41,17 @@ export class PlatformOrganizationBillingTasker extends Tasker<IPlatformOrganizat
return taskResponse;
}
- public async cancelUsageIncrement(data: { payload: { bookingUid: string } }): Promise<{ runId: string }> {
- const { payload } = data;
+ public async cancelUsageIncrement(data: {
+ payload: { bookingUid: string };
+ options?: TriggerOptions;
+ }): Promise<{ runId: string }> {
+ const { payload, options } = data;
let taskResponse: {
runId: string;
} = { runId: "task-not-found" };
try {
- taskResponse = await this.dispatch("cancelUsageIncrement", payload);
+ taskResponse = await this.dispatch("cancelUsageIncrement", payload, options);
this.logger.info(`PlatformOrganizationBillingTasker cancelUsageIncrement success:`, taskResponse, {
bookingUid: payload.bookingUid,
@@ -64,16 +67,16 @@ export class PlatformOrganizationBillingTasker extends Tasker<IPlatformOrganizat
}
public async rescheduleUsageIncrement(data: {
- payload: { bookingUid: string };
- options: { delay: NonNullable<TriggerOptions["delay"]> };
+ payload: { bookingUid: string; rescheduledTime: Date };
+ options?: TriggerOptions;
}): Promise<{ runId: string }> {
- const { payload } = data;
+ const { payload, options } = data;
let taskResponse: {
runId: string;
} = { runId: "task-not-found" };
try {
- taskResponse = await this.dispatch("rescheduleUsageIncrement", payload, data.options);
+ taskResponse = await this.dispatch("rescheduleUsageIncrement", payload, options);
this.logger.info(`PlatformOrganizationBillingTasker rescheduleUsageIncrement success:`, taskResponse, {
bookingUid: payload.bookingUid,
});
diff --git a/packages/features/ee/organizations/lib/billing/tasker/trigger/reschedule-usage-increment.ts b/packages/features/ee/organizations/lib/billing/tasker/trigger/reschedule-usage-increment.ts
index c7114af6aee..4a61858f0db 100644
--- a/packages/features/ee/organizations/lib/billing/tasker/trigger/reschedule-usage-increment.ts
+++ b/packages/features/ee/organizations/lib/billing/tasker/trigger/reschedule-usage-increment.ts
@@ -24,6 +24,6 @@ export const rescheduleUsageIncrement: TaskWithSchema<
return;
}
- await runs.cancel(runId);
+ await runs.reschedule(runId, { delay: payload.rescheduledTime });
},
});
diff --git a/packages/features/ee/organizations/lib/billing/tasker/trigger/schema.ts b/packages/features/ee/organizations/lib/billing/tasker/trigger/schema.ts
index 6a5af1eafd3..596438c1238 100644
--- a/packages/features/ee/organizations/lib/billing/tasker/trigger/schema.ts
+++ b/packages/features/ee/organizations/lib/billing/tasker/trigger/schema.ts
@@ -35,15 +35,19 @@ export const platformBillingCancelUsageIncrementTaskSchema: z.ZodObject<
export const platformBillingRescheduleUsageIncrementTaskSchema: z.ZodObject<
{
bookingUid: z.ZodString;
+ rescheduledTime: z.ZodDate;
},
"strip",
z.ZodTypeAny,
{
bookingUid: string;
+ rescheduledTime: Date;
},
{
bookingUid: string;
+ rescheduledTime: Date;
}
> = z.object({
bookingUid: z.string(),
+ rescheduledTime: z.coerce.date(),
});
diff --git a/packages/features/ee/organizations/lib/billing/tasker/types.ts b/packages/features/ee/organizations/lib/billing/tasker/types.ts
index 49f6a5bded7..efec6717397 100644
--- a/packages/features/ee/organizations/lib/billing/tasker/types.ts
+++ b/packages/features/ee/organizations/lib/billing/tasker/types.ts
@@ -14,11 +14,14 @@ export interface IPlatformOrganizationBillingTasker {
options?: TriggerOptions
): Promise<{ runId: string }>;
- cancelUsageIncrement(payload: { bookingUid: string }): Promise<{ runId: string }>;
+ cancelUsageIncrement(payload: { bookingUid: string }, options?: TriggerOptions): Promise<{ runId: string }>;
rescheduleUsageIncrement(
- payload: { bookingUid: string },
- options: { delay: NonNullable<TriggerOptions["delay"]> }
+ payload: {
+ bookingUid: string;
+ rescheduledTime: Date;
+ },
+ options?: TriggerOptions
): Promise<{ runId: string }>;
}