refactored monorepo for more projects
This commit is contained in:
parent
4632c174dc
commit
9492f1b15e
180 changed files with 1438 additions and 424 deletions
|
|
@ -12,6 +12,20 @@ export const browserConfigSchema = z.object({
|
|||
|
||||
export const queueConfigSchema = z.object({
|
||||
enabled: z.boolean().optional().default(true),
|
||||
workers: z.number().optional().default(1),
|
||||
concurrency: z.number().optional().default(1),
|
||||
enableScheduledJobs: z.boolean().optional().default(true),
|
||||
delayWorkerStart: z.boolean().optional().default(false),
|
||||
defaultJobOptions: z.object({
|
||||
attempts: z.number().default(3),
|
||||
backoff: z.object({
|
||||
type: z.enum(['exponential', 'fixed']).default('exponential'),
|
||||
delay: z.number().default(1000),
|
||||
}).default({}),
|
||||
removeOnComplete: z.number().default(100),
|
||||
removeOnFail: z.number().default(50),
|
||||
timeout: z.number().optional(),
|
||||
}).optional().default({}),
|
||||
});
|
||||
|
||||
export type ProxyConfig = z.infer<typeof proxyConfigSchema>;
|
||||
|
|
|
|||
|
|
@ -73,26 +73,24 @@ export class ServiceContainerBuilder {
|
|||
|
||||
private applyServiceOptions(config: Partial<AppConfig>): AppConfig {
|
||||
return {
|
||||
redis: {
|
||||
redis: config.redis || {
|
||||
enabled: this.options.enableCache ?? true,
|
||||
host: config.redis?.host || 'localhost',
|
||||
port: config.redis?.port || 6379,
|
||||
password: config.redis?.password,
|
||||
username: config.redis?.username,
|
||||
db: config.redis?.db || 0,
|
||||
host: 'localhost',
|
||||
port: 6379,
|
||||
db: 0,
|
||||
},
|
||||
mongodb: {
|
||||
mongodb: config.mongodb || {
|
||||
enabled: this.options.enableMongoDB ?? true,
|
||||
uri: config.mongodb?.uri || '',
|
||||
database: config.mongodb?.database || '',
|
||||
uri: '',
|
||||
database: '',
|
||||
},
|
||||
postgres: {
|
||||
postgres: config.postgres || {
|
||||
enabled: this.options.enablePostgres ?? true,
|
||||
host: config.postgres?.host || 'localhost',
|
||||
port: config.postgres?.port || 5432,
|
||||
database: config.postgres?.database || '',
|
||||
user: config.postgres?.user || '',
|
||||
password: config.postgres?.password || '',
|
||||
host: 'localhost',
|
||||
port: 5432,
|
||||
database: 'postgres',
|
||||
user: 'postgres',
|
||||
password: 'postgres',
|
||||
},
|
||||
questdb: this.options.enableQuestDB ? (config.questdb || {
|
||||
enabled: true,
|
||||
|
|
@ -104,7 +102,19 @@ export class ServiceContainerBuilder {
|
|||
}) : undefined,
|
||||
proxy: this.options.enableProxy ? (config.proxy || { cachePrefix: 'proxy:', ttl: 3600 }) : undefined,
|
||||
browser: this.options.enableBrowser ? (config.browser || { headless: true, timeout: 30000 }) : undefined,
|
||||
queue: this.options.enableQueue ? { enabled: this.options.enableQueue } : undefined,
|
||||
queue: this.options.enableQueue ? (config.queue || {
|
||||
enabled: true,
|
||||
workers: 1,
|
||||
concurrency: 1,
|
||||
enableScheduledJobs: true,
|
||||
delayWorkerStart: false,
|
||||
defaultJobOptions: {
|
||||
attempts: 3,
|
||||
backoff: { type: 'exponential' as const, delay: 1000 },
|
||||
removeOnComplete: 100,
|
||||
removeOnFail: 50,
|
||||
}
|
||||
}) : undefined,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -133,8 +143,8 @@ export class ServiceContainerBuilder {
|
|||
}
|
||||
|
||||
private transformStockBotConfig(config: AppConfig | StockBotAppConfig): Partial<AppConfig> {
|
||||
// If it's already in the new format, return as is
|
||||
if ('redis' in config) {
|
||||
// If it's already in the new format (has redis AND postgres at top level), return as is
|
||||
if ('redis' in config && 'postgres' in config && 'mongodb' in config) {
|
||||
return config as AppConfig;
|
||||
}
|
||||
|
||||
|
|
@ -149,18 +159,17 @@ export class ServiceContainerBuilder {
|
|||
db: stockBotConfig.database.dragonfly.db || 0,
|
||||
} : undefined,
|
||||
mongodb: stockBotConfig.database?.mongodb ? {
|
||||
enabled: true,
|
||||
uri: stockBotConfig.database.mongodb.uri ||
|
||||
`mongodb://${stockBotConfig.database.mongodb.user || ''}:${stockBotConfig.database.mongodb.password || ''}@${stockBotConfig.database.mongodb.host || 'localhost'}:${stockBotConfig.database.mongodb.port || 27017}/${stockBotConfig.database.mongodb.database || 'test'}?authSource=${stockBotConfig.database.mongodb.authSource || 'admin'}`,
|
||||
database: stockBotConfig.database.mongodb.database || 'test',
|
||||
enabled: stockBotConfig.database.mongodb.enabled ?? true,
|
||||
uri: stockBotConfig.database.mongodb.uri,
|
||||
database: stockBotConfig.database.mongodb.database,
|
||||
} : undefined,
|
||||
postgres: stockBotConfig.database?.postgres ? {
|
||||
enabled: true,
|
||||
host: stockBotConfig.database.postgres.host || 'localhost',
|
||||
port: stockBotConfig.database.postgres.port || 5432,
|
||||
database: stockBotConfig.database.postgres.database || 'test',
|
||||
user: stockBotConfig.database.postgres.user || 'test',
|
||||
password: stockBotConfig.database.postgres.password || 'test',
|
||||
enabled: stockBotConfig.database.postgres.enabled ?? true,
|
||||
host: stockBotConfig.database.postgres.host,
|
||||
port: stockBotConfig.database.postgres.port,
|
||||
database: stockBotConfig.database.postgres.database,
|
||||
user: stockBotConfig.database.postgres.user,
|
||||
password: stockBotConfig.database.postgres.password,
|
||||
} : undefined,
|
||||
questdb: stockBotConfig.database?.questdb ? {
|
||||
enabled: true,
|
||||
|
|
@ -170,6 +179,9 @@ export class ServiceContainerBuilder {
|
|||
influxPort: stockBotConfig.database.questdb.ilpPort || 9009,
|
||||
database: stockBotConfig.database.questdb.database || 'questdb',
|
||||
} : undefined,
|
||||
queue: stockBotConfig.queue,
|
||||
browser: stockBotConfig.browser,
|
||||
proxy: stockBotConfig.proxy,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ export function registerDatabaseServices(
|
|||
port: parseInt(uriMatch?.[4] || '27017'),
|
||||
database: config.mongodb.database,
|
||||
username: uriMatch?.[1],
|
||||
password: uriMatch?.[2],
|
||||
password: uriMatch?.[2] ? String(uriMatch?.[2]) : undefined,
|
||||
authSource: uriMatch?.[6] || 'admin',
|
||||
uri: config.mongodb.uri,
|
||||
};
|
||||
|
|
@ -37,16 +37,19 @@ export function registerDatabaseServices(
|
|||
if (config.postgres.enabled) {
|
||||
container.register({
|
||||
postgresClient: asFunction(({ logger }) => {
|
||||
return new PostgreSQLClient(
|
||||
{
|
||||
host: config.postgres.host,
|
||||
port: config.postgres.port,
|
||||
database: config.postgres.database,
|
||||
username: config.postgres.user,
|
||||
password: config.postgres.password,
|
||||
},
|
||||
logger
|
||||
);
|
||||
const pgConfig = {
|
||||
host: config.postgres.host,
|
||||
port: config.postgres.port,
|
||||
database: config.postgres.database,
|
||||
username: config.postgres.user,
|
||||
password: String(config.postgres.password), // Ensure password is a string
|
||||
};
|
||||
|
||||
logger.debug('PostgreSQL config:', {
|
||||
...pgConfig,
|
||||
password: pgConfig.password ? '***' : 'NO_PASSWORD',
|
||||
});
|
||||
return new PostgreSQLClient(pgConfig, logger);
|
||||
}).singleton(),
|
||||
});
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -56,19 +56,12 @@ export function registerApplicationServices(
|
|||
db: config.redis.db,
|
||||
},
|
||||
defaultQueueOptions: {
|
||||
workers: 1,
|
||||
concurrency: 1,
|
||||
defaultJobOptions: {
|
||||
removeOnComplete: 100,
|
||||
removeOnFail: 50,
|
||||
attempts: 3,
|
||||
backoff: {
|
||||
type: 'exponential',
|
||||
delay: 1000,
|
||||
},
|
||||
},
|
||||
workers: config.queue!.workers || 1,
|
||||
concurrency: config.queue!.concurrency || 1,
|
||||
defaultJobOptions: config.queue!.defaultJobOptions,
|
||||
},
|
||||
enableScheduledJobs: true,
|
||||
enableScheduledJobs: config.queue!.enableScheduledJobs ?? true,
|
||||
delayWorkerStart: config.queue!.delayWorkerStart ?? false,
|
||||
};
|
||||
return new QueueManager(queueConfig, logger);
|
||||
}).singleton(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue