Files
stack/apps/gateway/src/log/cron.service.ts
Jason Woltje 4c37162b55
All checks were successful
ci/woodpecker/push/ci Pipeline was successful
fix(gateway): add missing @Inject() decorators causing silent startup hang
tsx/esbuild doesn't support emitDecoratorMetadata, so NestJS can't
infer constructor parameter types at runtime. Three services were
missing explicit @Inject() decorators:

- SummarizationService: EmbeddingService parameter
- CronService: SummarizationService parameter
- SkillsController: SkillsService parameter

Without these, NestJS DI hangs forever during onModuleInit resolution
with no error output — the process silently exits (or hangs with a
keepAlive).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-14 20:51:36 -05:00

51 lines
1.5 KiB
TypeScript

import {
Inject,
Injectable,
Logger,
type OnModuleInit,
type OnModuleDestroy,
} from '@nestjs/common';
import cron from 'node-cron';
import { SummarizationService } from './summarization.service.js';
@Injectable()
export class CronService implements OnModuleInit, OnModuleDestroy {
private readonly logger = new Logger(CronService.name);
private readonly tasks: cron.ScheduledTask[] = [];
constructor(@Inject(SummarizationService) private readonly summarization: SummarizationService) {}
onModuleInit(): void {
const summarizationSchedule = process.env['SUMMARIZATION_CRON'] ?? '0 */6 * * *'; // every 6 hours
const tierManagementSchedule = process.env['TIER_MANAGEMENT_CRON'] ?? '0 3 * * *'; // daily at 3am
this.tasks.push(
cron.schedule(summarizationSchedule, () => {
this.summarization.runSummarization().catch((err) => {
this.logger.error(`Scheduled summarization failed: ${err}`);
});
}),
);
this.tasks.push(
cron.schedule(tierManagementSchedule, () => {
this.summarization.runTierManagement().catch((err) => {
this.logger.error(`Scheduled tier management failed: ${err}`);
});
}),
);
this.logger.log(
`Cron scheduled: summarization="${summarizationSchedule}", tier="${tierManagementSchedule}"`,
);
}
onModuleDestroy(): void {
for (const task of this.tasks) {
task.stop();
}
this.tasks.length = 0;
this.logger.log('Cron tasks stopped');
}
}