Skip to content

Commit

Permalink
feat(api): validate environment variables in workers
Browse files Browse the repository at this point in the history
Co-authored-by: Aurélie Crouillebois <[email protected]>
Co-authored-by: Vincent Hardouin <[email protected]>
  • Loading branch information
3 people committed Feb 28, 2025
1 parent c0f272e commit b538e98
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion api/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import PgBoss from 'pg-boss';
import { databaseConnections } from './db/database-connections.js';
import { Metrics } from './src/monitoring/infrastructure/metrics.js';
import { JobGroup } from './src/shared/application/jobs/job-controller.js';
import { config } from './src/shared/config.js';
import { config, schema as configSchema } from './src/shared/config.js';
import { learningContentCache } from './src/shared/infrastructure/caches/learning-content-cache.js';
import { JobQueue } from './src/shared/infrastructure/jobs/JobQueue.js';
import { quitAllStorages } from './src/shared/infrastructure/key-value-storages/index.js';
import { importNamedExportFromFile } from './src/shared/infrastructure/utils/import-named-exports-from-directory.js';
import { child } from './src/shared/infrastructure/utils/logger.js';
import { validateEnvironmentVariables } from './src/shared/infrastructure/validate-environment-variables.js';

const logger = child('worker', { event: 'worker' });

Expand Down Expand Up @@ -137,8 +138,11 @@ export async function registerJobs({ jobGroups, dependencies = { startPgBoss, cr
const isRunningFromCli = import.meta.filename === process.argv[1];

async function main() {
validateEnvironmentVariables(configSchema);

const jobGroup = process.argv[2] ? JobGroup[process.argv[2]?.toUpperCase()] : JobGroup.DEFAULT;
await registerJobs({ jobGroups: [jobGroup] });

process.on('SIGINT', async () => {
await quitAllStorages();
await metrics.clearMetrics();
Expand All @@ -150,5 +154,6 @@ async function main() {
if (isRunningFromCli) {
main().catch((err) => {
logger.error({ err }, 'worker crashed');
process.exit(1); // eslint-disable-line n/no-process-exit
});
}

0 comments on commit b538e98

Please sign in to comment.