mirror of
https://github.com/fosrl/pangolin.git
synced 2026-02-24 22:06:38 +00:00
Dont log to stripe
This commit is contained in:
@@ -18,6 +18,7 @@ import { sendToClient } from "#dynamic/routers/ws";
|
|||||||
import { build } from "@server/build";
|
import { build } from "@server/build";
|
||||||
import { s3Client } from "@server/lib/s3";
|
import { s3Client } from "@server/lib/s3";
|
||||||
import cache from "@server/lib/cache";
|
import cache from "@server/lib/cache";
|
||||||
|
import privateConfig from "@server/private/lib/config";
|
||||||
|
|
||||||
interface StripeEvent {
|
interface StripeEvent {
|
||||||
identifier?: string;
|
identifier?: string;
|
||||||
@@ -30,9 +31,7 @@ interface StripeEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function noop() {
|
export function noop() {
|
||||||
if (
|
if (build !== "saas") {
|
||||||
build !== "saas"
|
|
||||||
) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -48,29 +47,39 @@ export class UsageService {
|
|||||||
if (noop()) {
|
if (noop()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.bucketName = process.env.S3_BUCKET || undefined;
|
this.bucketName = process.env.S3_BUCKET || undefined;
|
||||||
|
|
||||||
// Periodically check and upload events
|
if ( // Only set up event uploading if usage reporting is enabled and bucket name is configured
|
||||||
setInterval(() => {
|
privateConfig.getRawPrivateConfig().flags.usage_reporting &&
|
||||||
this.checkAndUploadEvents().catch((err) => {
|
this.bucketName
|
||||||
logger.error("Error in periodic event upload:", err);
|
) {
|
||||||
|
// Periodically check and upload events
|
||||||
|
setInterval(() => {
|
||||||
|
this.checkAndUploadEvents().catch((err) => {
|
||||||
|
logger.error("Error in periodic event upload:", err);
|
||||||
|
});
|
||||||
|
}, 30000); // every 30 seconds
|
||||||
|
|
||||||
|
// Handle graceful shutdown on SIGTERM
|
||||||
|
process.on("SIGTERM", async () => {
|
||||||
|
logger.info(
|
||||||
|
"SIGTERM received, uploading events before shutdown..."
|
||||||
|
);
|
||||||
|
await this.forceUpload();
|
||||||
|
logger.info("Events uploaded, proceeding with shutdown");
|
||||||
});
|
});
|
||||||
}, 30000); // every 30 seconds
|
|
||||||
|
|
||||||
// Handle graceful shutdown on SIGTERM
|
// Handle SIGINT as well (Ctrl+C)
|
||||||
process.on("SIGTERM", async () => {
|
process.on("SIGINT", async () => {
|
||||||
logger.info("SIGTERM received, uploading events before shutdown...");
|
logger.info(
|
||||||
await this.forceUpload();
|
"SIGINT received, uploading events before shutdown..."
|
||||||
logger.info("Events uploaded, proceeding with shutdown");
|
);
|
||||||
});
|
await this.forceUpload();
|
||||||
|
logger.info("Events uploaded, proceeding with shutdown");
|
||||||
// Handle SIGINT as well (Ctrl+C)
|
process.exit(0);
|
||||||
process.on("SIGINT", async () => {
|
});
|
||||||
logger.info("SIGINT received, uploading events before shutdown...");
|
}
|
||||||
await this.forceUpload();
|
|
||||||
logger.info("Events uploaded, proceeding with shutdown");
|
|
||||||
process.exit(0);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -129,7 +138,9 @@ export class UsageService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Log event for Stripe
|
// Log event for Stripe
|
||||||
await this.logStripeEvent(featureId, value, customerId);
|
if (privateConfig.getRawPrivateConfig().flags.usage_reporting) {
|
||||||
|
await this.logStripeEvent(featureId, value, customerId);
|
||||||
|
}
|
||||||
|
|
||||||
return usage || null;
|
return usage || null;
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
@@ -306,7 +317,9 @@ export class UsageService {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
await this.logStripeEvent(featureId, value || 0, customerId);
|
if (privateConfig.getRawPrivateConfig().flags.usage_reporting) {
|
||||||
|
await this.logStripeEvent(featureId, value || 0, customerId);
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error(
|
logger.error(
|
||||||
`Failed to update daily usage for ${orgId}/${featureId}:`,
|
`Failed to update daily usage for ${orgId}/${featureId}:`,
|
||||||
|
|||||||
@@ -95,7 +95,8 @@ export const privateConfigSchema = z.object({
|
|||||||
.object({
|
.object({
|
||||||
enable_redis: z.boolean().optional().default(false),
|
enable_redis: z.boolean().optional().default(false),
|
||||||
use_pangolin_dns: z.boolean().optional().default(false),
|
use_pangolin_dns: z.boolean().optional().default(false),
|
||||||
use_org_only_idp: z.boolean().optional().default(false)
|
use_org_only_idp: z.boolean().optional().default(false),
|
||||||
|
usage_reporting: z.boolean().optional().default(false)
|
||||||
})
|
})
|
||||||
.optional()
|
.optional()
|
||||||
.prefault({}),
|
.prefault({}),
|
||||||
|
|||||||
Reference in New Issue
Block a user