fix: platform billing reschedule usage increment via trigger.dev (#27483)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
-1
@@ -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";
|
||||
|
||||
|
||||
+12
-9
@@ -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,
|
||||
});
|
||||
|
||||
+1
-1
@@ -24,6 +24,6 @@ export const rescheduleUsageIncrement: TaskWithSchema<
|
||||
return;
|
||||
}
|
||||
|
||||
await runs.cancel(runId);
|
||||
await runs.reschedule(runId, { delay: payload.rescheduledTime });
|
||||
},
|
||||
});
|
||||
|
||||
@@ -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(),
|
||||
});
|
||||
|
||||
@@ -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 }>;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user