initial wcag-ada

This commit is contained in:
Boki 2025-06-28 11:11:34 -04:00
parent 042b8cb83a
commit d52cfe7de2
112 changed files with 9069 additions and 0 deletions

View 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,
});

View 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;

View 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,
});
}

View 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');
});
}