feat(MED-105): reset instrumentation.ts
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
|
/**
|
||||||
|
* This file is used to register monitoring instrumentation
|
||||||
|
* for your Next.js application.
|
||||||
|
*/
|
||||||
import { type Instrumentation } from 'next';
|
import { type Instrumentation } from 'next';
|
||||||
|
|
||||||
const isEnabledInDev = process.env.ENABLE_LOCAL_JOBS === 'true';
|
|
||||||
|
|
||||||
const isEnabledScheduler = false as boolean;
|
|
||||||
|
|
||||||
export async function register() {
|
export async function register() {
|
||||||
const { registerMonitoringInstrumentation } = await import(
|
const { registerMonitoringInstrumentation } = await import(
|
||||||
'@kit/monitoring/instrumentation'
|
'@kit/monitoring/instrumentation'
|
||||||
@@ -12,11 +12,6 @@ export async function register() {
|
|||||||
// Register monitoring instrumentation
|
// Register monitoring instrumentation
|
||||||
// based on the MONITORING_PROVIDER environment variable.
|
// based on the MONITORING_PROVIDER environment variable.
|
||||||
await registerMonitoringInstrumentation();
|
await registerMonitoringInstrumentation();
|
||||||
|
|
||||||
// Register lightweight in-process job scheduler
|
|
||||||
if (isEnabledScheduler) {
|
|
||||||
await registerJobScheduler();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -26,58 +21,10 @@ export async function register() {
|
|||||||
* @param err
|
* @param err
|
||||||
*/
|
*/
|
||||||
export const onRequestError: Instrumentation.onRequestError = async (err) => {
|
export const onRequestError: Instrumentation.onRequestError = async (err) => {
|
||||||
// const { getServerMonitoringService } = await import('@kit/monitoring/server');
|
const { getServerMonitoringService } = await import('@kit/monitoring/server');
|
||||||
|
|
||||||
// const service = await getServerMonitoringService();
|
const service = await getServerMonitoringService();
|
||||||
|
|
||||||
// await service.ready();
|
await service.ready();
|
||||||
// await service.captureException(err as Error);
|
await service.captureException(err as Error);
|
||||||
};
|
};
|
||||||
|
|
||||||
async function registerJobScheduler() {
|
|
||||||
const isProd = process.env.NODE_ENV === 'production';
|
|
||||||
if (!isProd && !isEnabledInDev) {
|
|
||||||
console.info('Job scheduler disabled');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Prevent duplicate intervals on hot reloads/dev
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
||||||
const globalAny = globalThis as any;
|
|
||||||
if (globalAny.__mrJobSchedulerInitialized) {
|
|
||||||
console.info('Job scheduler already initialized');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
globalAny.__mrJobSchedulerInitialized = true;
|
|
||||||
|
|
||||||
let isRunning = false;
|
|
||||||
|
|
||||||
const runSyncAnalysisResults = async () => {
|
|
||||||
if (isRunning) {
|
|
||||||
console.info('Scheduled job syncAnalysisResults skipped: previous run still in progress');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
isRunning = true;
|
|
||||||
try {
|
|
||||||
try {
|
|
||||||
const { default: loadEnv } = await import('./app/api/job/handler/load-env');
|
|
||||||
loadEnv();
|
|
||||||
} catch {
|
|
||||||
// ignore if not available or already loaded
|
|
||||||
}
|
|
||||||
|
|
||||||
const { default: syncAnalysisResults } = await import(
|
|
||||||
'./app/api/job/handler/sync-analysis-results'
|
|
||||||
);
|
|
||||||
await syncAnalysisResults();
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Scheduled job syncAnalysisResults failed:', error);
|
|
||||||
} finally {
|
|
||||||
isRunning = false;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Run every 10 minutes
|
|
||||||
setTimeout(runSyncAnalysisResults, 15_000);
|
|
||||||
setInterval(runSyncAnalysisResults, 10 * 60 * 1000);
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user