Files
calendar/packages/features/trigger.config.ts
T
MorganGitHubDevin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
c60addc528 feat: add PlatformOrganizationBillingTasker with sync and trigger.dev versions (#26803)
* feat: add PlatformOrganizationBillingTasker with sync and trigger.dev versions

- Create PlatformOrganizationBillingTasker extending Tasker base class
- Add sync tasker (PlatformOrganizationBillingSyncTasker) for synchronous execution
- Add trigger.dev tasker (PlatformOrganizationBillingTriggerTasker) for async execution
- Create trigger.dev task for incrementing subscription usage
- Add PlatformOrganizationBillingTaskService with business logic
- Add PlatformOrganizationBillingRepository for data access
- Add createSubscriptionUsageRecord method to StripeBillingService
- Follow BookingEmailAndSmsTasker pattern for consistency

Co-Authored-By: morgan@cal.com <morgan@cal.com>

* refactor: move repository methods per PR feedback

- Move findPlatformOrgByUserId to OrganizationRepository
- Create new PlatformBillingRepository for billing queries
- Remove PlatformOrganizationBillingRepository (consolidated)
- Update task service and trigger.dev task to use new repositories

Co-Authored-By: morgan@cal.com <morgan@cal.com>

* feat: add DI using @evyweb/ioctopus for platform billing tasker

- Create di/tasker/ directory following BookingEmailAndSmsTasker pattern
- Add tokens.ts with DI tokens for all billing tasker classes
- Add module files for PlatformBillingRepository, TaskService, SyncTasker, TriggerTasker, Tasker
- Add container files with getter functions
- Update trigger.dev task to use DI container instead of manual instantiation

Co-Authored-By: morgan@cal.com <morgan@cal.com>

* refactor: add select statement to PlatformBillingRepository.findByTeamId

Only select subscriptionId field since that's the only field used by the task service

Co-Authored-By: morgan@cal.com <morgan@cal.com>

* feat: add NestJS DI modules for platform billing tasker in API v2

- Add platform billing tasker exports to platform-libraries/organizations.ts
- Export IBillingProviderService type from platform-libraries
- Create StripeBillingProviderService wrapper implementing IBillingProviderService
- Create PrismaPlatformBillingRepository extending PlatformBillingRepository
- Create NestJS service wrappers for all platform billing tasker classes
- Create PlatformBillingTaskerModule with all providers and exports
- Update PlatformOrganizationBillingTaskService to use Pick<IBillingProviderService>

Co-Authored-By: morgan@cal.com <morgan@cal.com>

* feat: handle cancel and reschedule usage

* fix: restore IsUserInBillingOrg to billing module providers

Co-Authored-By: morgan@cal.com <morgan@cal.com>

* chore: add idempotency key

* fix: just log error]

* fix: logger and typo

* fix: address Cubic AI review feedback (high confidence issues)

- Fix grammar error: 'Delayed task are' -> 'Delayed tasks are' in PlatformOrganizationBillingSyncTasker.ts (3 occurrences)
- Re-throw error after logging in increment-usage.ts to enable trigger.dev retry mechanism

Co-Authored-By: unknown <>

* fix: remove duplicate code and use DI instead

* fix: remove orThrow on find first in findPlatformOrgByUserId

* refactor: prevent usage increment task from re-throwing errors

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-01-20 15:26:50 +09:00

75 lines
2.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import process from "node:process";
import { syncVercelEnvVars } from "@trigger.dev/build/extensions/core";
import { defineConfig } from "@trigger.dev/sdk";
import dotEnv from "dotenv";
dotEnv.config({ path: "../../.env" });
const canSyncEnvVars = Boolean(
process.env.TRIGGER_DEV_VERCEL_ACCESS_TOKEN &&
process.env.TRIGGER_DEV_VERCEL_PROJECT_ID &&
process.env.TRIGGER_DEV_VERCEL_TEAM_ID
);
export default defineConfig({
// Your project ref from the Trigger.dev dashboard
project: process.env.TRIGGER_DEV_PROJECT_REF ?? "", // e.g., "proj_abc123"
// Directories containing your tasks
dirs: [
"./bookings/lib/tasker/trigger/notifications",
"./calendars/lib/tasker/trigger",
"./ee/billing/service/proration/tasker/trigger",
"./ee/organizations/lib/billing/tasker/trigger",
], // Customize based on your project structure
// Retry configuration
retries: {
enabledInDev: false, // Enable retries in development
default: {
maxAttempts: 3,
minTimeoutInMs: 1000,
maxTimeoutInMs: 10000,
factor: 2,
randomize: true,
},
},
// Keep the process alive after the task has finished running so the next task doesnt have to wait for the process to start up again.
processKeepAlive: true,
// Build configuration (optional)
build: {
external: [
"@prisma/client",
"nodemailer",
"jsdom",
"playwright-core",
"playwright",
"chromium-bidi",
"http-cookie-agent",
"deasync",
],
extensions: canSyncEnvVars
? [
syncVercelEnvVars({
// A personal access token created in your Vercel account settings
// Used to authenticate API requests to Vercel
// Generate at: https://vercel.com/account/tokens
vercelAccessToken: process.env.TRIGGER_DEV_VERCEL_ACCESS_TOKEN,
// The unique identifier of your Vercel project
// Found in Project Settings > General > Project ID
projectId: process.env.TRIGGER_DEV_VERCEL_PROJECT_ID,
// Optional: The ID of your Vercel team
// Only required for team projects
// Found in Team Settings > General > Team ID
vercelTeamId: process.env.TRIGGER_DEV_VERCEL_TEAM_ID,
}),
]
: [],
},
// Max duration of a task in seconds
maxDuration: 600,
});