Skip to content

Commit

Permalink
Improved comments on /App/FeatureSet/Workers/Jobs/MeteredPlan/ReportT…
Browse files Browse the repository at this point in the history
…elemetryMeteredPlan.ts
  • Loading branch information
OneUptime Copilot committed Sep 5, 2024
1 parent 5bfe387 commit eebda0f
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,24 @@ 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.",
);
return;
}

// Fetch all projects with no specific query and a maximum limit.
const projects: Array<Project> = await ProjectService.findBy({
query: {},
select: {
Expand All @@ -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,
);
Expand Down

0 comments on commit eebda0f

Please sign in to comment.