initial wcag-ada
This commit is contained in:
parent
042b8cb83a
commit
d52cfe7de2
112 changed files with 9069 additions and 0 deletions
16
apps/wcag-ada/worker/src/utils/logger.ts
Normal file
16
apps/wcag-ada/worker/src/utils/logger.ts
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import pino from 'pino';
|
||||
import { getWcagConfig } from '@wcag-ada/config';
|
||||
|
||||
const config = getWcagConfig();
|
||||
|
||||
export const logger = pino({
|
||||
level: config.log.level,
|
||||
transport: config.environment === 'development' ? {
|
||||
target: 'pino-pretty',
|
||||
options: {
|
||||
colorize: true,
|
||||
ignore: 'pid,hostname',
|
||||
translateTime: 'HH:MM:ss',
|
||||
},
|
||||
} : undefined,
|
||||
});
|
||||
14
apps/wcag-ada/worker/src/utils/prisma.ts
Normal file
14
apps/wcag-ada/worker/src/utils/prisma.ts
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import { PrismaClient } from '@prisma/client';
|
||||
import { getWcagConfig } from '@wcag-ada/config';
|
||||
|
||||
const config = getWcagConfig();
|
||||
|
||||
const globalForPrisma = global as unknown as { prisma: PrismaClient };
|
||||
|
||||
export const prisma =
|
||||
globalForPrisma.prisma ||
|
||||
new PrismaClient({
|
||||
log: config.environment === 'development' ? ['error', 'warn'] : ['error'],
|
||||
});
|
||||
|
||||
if (config.environment !== 'production') globalForPrisma.prisma = prisma;
|
||||
14
apps/wcag-ada/worker/src/utils/redis.ts
Normal file
14
apps/wcag-ada/worker/src/utils/redis.ts
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import Redis from 'ioredis';
|
||||
import { getWorkerConfig } from '@wcag-ada/config';
|
||||
|
||||
const workerConfig = getWorkerConfig();
|
||||
|
||||
export function createRedisConnection(): Redis {
|
||||
return new Redis({
|
||||
host: workerConfig.redis.host,
|
||||
port: workerConfig.redis.port,
|
||||
password: workerConfig.redis.password,
|
||||
db: workerConfig.redis.db,
|
||||
maxRetriesPerRequest: workerConfig.redis.maxRetriesPerRequest,
|
||||
});
|
||||
}
|
||||
37
apps/wcag-ada/worker/src/utils/shutdown.ts
Normal file
37
apps/wcag-ada/worker/src/utils/shutdown.ts
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
import { logger } from './logger';
|
||||
|
||||
interface Stoppable {
|
||||
stop(): Promise<void>;
|
||||
}
|
||||
|
||||
export function gracefulShutdown(services: Stoppable[]): void {
|
||||
const shutdown = async (signal: string) => {
|
||||
logger.info(`Received ${signal} signal, starting graceful shutdown...`);
|
||||
|
||||
try {
|
||||
// Stop all services
|
||||
await Promise.all(services.map(service => service.stop()));
|
||||
|
||||
logger.info('Graceful shutdown completed');
|
||||
process.exit(0);
|
||||
} catch (error) {
|
||||
logger.error('Error during shutdown', error);
|
||||
process.exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
// Handle shutdown signals
|
||||
process.on('SIGTERM', () => shutdown('SIGTERM'));
|
||||
process.on('SIGINT', () => shutdown('SIGINT'));
|
||||
|
||||
// Handle uncaught errors
|
||||
process.on('uncaughtException', (error) => {
|
||||
logger.error('Uncaught exception', error);
|
||||
shutdown('uncaughtException');
|
||||
});
|
||||
|
||||
process.on('unhandledRejection', (reason, promise) => {
|
||||
logger.error('Unhandled rejection', { reason, promise });
|
||||
shutdown('unhandledRejection');
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue