Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved comments on /App/FeatureSet/Workers/Jobs/MeteredPlan/ReportTelemetryMeteredPlan.ts #1671

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading