diff --git a/App/FeatureSet/Workers/Jobs/MeteredPlan/ReportTelemetryMeteredPlan.ts b/App/FeatureSet/Workers/Jobs/MeteredPlan/ReportTelemetryMeteredPlan.ts index c38c2b29e96..0062e431f9e 100644 --- a/App/FeatureSet/Workers/Jobs/MeteredPlan/ReportTelemetryMeteredPlan.ts +++ b/App/FeatureSet/Workers/Jobs/MeteredPlan/ReportTelemetryMeteredPlan.ts @@ -17,13 +17,16 @@ import { import logger from "Common/Server/Utils/Logger"; import Project from "Common/Models/DatabaseModels/Project"; +// Setting up a cron job to report telemetry data for metered plans. RunCron( "MeteredPlan:ReportTelemetryMeteredPlan", { + // Schedule the cron job based on the environment (development or production). schedule: IsDevelopment ? EVERY_FIVE_MINUTE : EVERY_DAY, runOnStartup: true, }, async () => { + // Check if billing is enabled; if not, skip the job. if (!IsBillingEnabled) { logger.debug( "MeteredPlan:ReportTelemetryMeteredPlan Billing is not enabled. Skipping job.", @@ -31,6 +34,7 @@ RunCron( return; } + // Fetch all projects with no specific query and a maximum limit. const projects: Array = await ProjectService.findBy({ query: {}, select: { @@ -46,28 +50,34 @@ RunCron( for (const project of projects) { try { if (project.id) { + // Get the current plan for the project. const plan: { plan: PlanType | null; isSubscriptionUnpaid: boolean; } = await ProjectService.getCurrentPlan(project.id); + // If the subscription is unpaid, skip reporting. if (plan.isSubscriptionUnpaid) { - // ignore and report when subscription is active. continue; } + // Report log data ingest quantity. await LogDataIngestMeteredPlan.reportQuantityToBillingProvider( project.id, ); + // Sleep for 1 second to avoid overloading the billing provider. await Sleep.sleep(1000); + // Report metrics data ingest quantity. await MetricsDataIngestMeteredPlan.reportQuantityToBillingProvider( project.id, ); + // Sleep for 1 second to avoid overloading the billing provider. await Sleep.sleep(1000); + // Report traces data ingest quantity. await TracesDataIngestMetredPlan.reportQuantityToBillingProvider( project.id, );