Harden deploy gates, prod AUTH_SECRET, and Sentry error reporting.
Local Build and Deploy / deploy (push) Successful in 1m42s
Local Build and Deploy / deploy (push) Successful in 1m42s
Align onlyBuiltDependencies with the workspace, fail fast without AUTH_SECRET in production, and delete catalog_items via VARCHAR-safe SQL so page deletes do not leave orphans. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
1 parent
b9c6001f08
commit
6b884ad25a
12 files changed
+128
-50
No files matched your search
+31
-26
@@ -1,8 +1,32 @@
|
||||
import * as Sentry from "@sentry/nextjs";
|
||||
import { Cron } from "croner";
|
||||
import { env } from "../src/env";
|
||||
import { logger } from "../src/lib/logger";
|
||||
import { prisma } from "../src/lib/prisma";
|
||||
|
||||
function initWorkerSentry(): void {
|
||||
const dsn = process.env.SENTRY_DSN;
|
||||
if (!dsn || process.env.NODE_ENV !== "production") return;
|
||||
|
||||
Sentry.init({
|
||||
dsn,
|
||||
environment: process.env.NODE_ENV,
|
||||
release: process.env.APP_VERSION,
|
||||
tracesSampleRate: 0.05,
|
||||
});
|
||||
logger.info("Sentry initialized for jobs worker", { module: "jobs" });
|
||||
}
|
||||
|
||||
function captureWorkerError(err: unknown, context: string): void {
|
||||
logger.error(context, {
|
||||
module: "jobs",
|
||||
err: err instanceof Error ? err.message : String(err),
|
||||
});
|
||||
if (process.env.SENTRY_DSN) {
|
||||
Sentry.captureException(err);
|
||||
}
|
||||
}
|
||||
|
||||
async function backupEmulatorJar(): Promise<void> {
|
||||
if (!env.EMULATOR_JAR_PATH || !env.EMULATOR_BACKUP_DIR) return;
|
||||
|
||||
@@ -41,10 +65,7 @@ async function backupEmulatorJar(): Promise<void> {
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
logger.error("JAR backup failed", {
|
||||
module: "jobs",
|
||||
err: err instanceof Error ? err.message : String(err),
|
||||
});
|
||||
captureWorkerError(err, "JAR backup failed");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,10 +77,7 @@ async function cleanupOldLogs(): Promise<void> {
|
||||
});
|
||||
logger.info("Cleaned up login logs older than 30 days", { module: "jobs" });
|
||||
} catch (err) {
|
||||
logger.error("Log cleanup failed", {
|
||||
module: "jobs",
|
||||
err: err instanceof Error ? err.message : String(err),
|
||||
});
|
||||
captureWorkerError(err, "Log cleanup failed");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,24 +91,17 @@ async function cleanupOldSessions(): Promise<void> {
|
||||
module: "jobs",
|
||||
});
|
||||
} catch (err) {
|
||||
logger.error("Session cleanup failed", {
|
||||
module: "jobs",
|
||||
err: err instanceof Error ? err.message : String(err),
|
||||
});
|
||||
captureWorkerError(err, "Session cleanup failed");
|
||||
}
|
||||
}
|
||||
|
||||
async function main() {
|
||||
initWorkerSentry();
|
||||
logger.info("Worker started", { module: "jobs" });
|
||||
|
||||
if (env.EMULATOR_JAR_PATH && env.EMULATOR_BACKUP_DIR) {
|
||||
new Cron("0 3 * * *", () => {
|
||||
backupEmulatorJar().catch((e) =>
|
||||
logger.error("Backup error", {
|
||||
module: "jobs",
|
||||
err: e instanceof Error ? e.message : String(e),
|
||||
}),
|
||||
);
|
||||
backupEmulatorJar().catch((e) => captureWorkerError(e, "Backup error"));
|
||||
});
|
||||
logger.info("Scheduled: emulator JAR backup (daily 03:00)", {
|
||||
module: "jobs",
|
||||
@@ -99,10 +110,7 @@ async function main() {
|
||||
|
||||
new Cron("0 4 * * *", () => {
|
||||
Promise.all([cleanupOldLogs(), cleanupOldSessions()]).catch((e) =>
|
||||
logger.error("Cleanup error", {
|
||||
module: "jobs",
|
||||
err: e instanceof Error ? e.message : String(e),
|
||||
}),
|
||||
captureWorkerError(e, "Cleanup error"),
|
||||
);
|
||||
});
|
||||
logger.info("Scheduled: old data cleanup (daily 04:00)", { module: "jobs" });
|
||||
@@ -115,9 +123,6 @@ async function main() {
|
||||
}
|
||||
|
||||
main().catch((err) => {
|
||||
logger.error("Fatal", {
|
||||
module: "jobs",
|
||||
err: err instanceof Error ? err.message : String(err),
|
||||
});
|
||||
captureWorkerError(err, "Fatal");
|
||||
process.exit(1);
|
||||
});
|
||||
Reference in new issue
Block a user