starting data-sync service

This commit is contained in:
Boki 2025-06-18 19:08:51 -04:00
parent 96f515a76b
commit bd8a5bfe9e
13 changed files with 43 additions and 210 deletions

View file

@ -2,6 +2,14 @@
"service": {
"name": "data-sync-service",
"port": 3005,
"environment": "development"
"host": "0.0.0.0",
"healthCheckPath": "/health",
"metricsPath": "/metrics",
"shutdownTimeout": 30000,
"cors": {
"enabled": true,
"origin": "*",
"credentials": false
}
}
}

View file

@ -3,7 +3,7 @@
*/
import { Hono } from 'hono';
import { cors } from 'hono/cors';
import { initializeConfig, getServiceConfig, getLoggingConfig } from '@stock-bot/config-new';
import { initializeConfig, getServiceConfig, getLoggingConfig, getDatabaseConfig } from '@stock-bot/config-new';
import { getLogger, shutdownLoggers, setLoggerConfig } from '@stock-bot/logger';
import { createAndConnectMongoDBClient, MongoDBClient } from '@stock-bot/mongodb-client';
import { createAndConnectPostgreSQLClient, PostgreSQLClient } from '@stock-bot/postgres-client';
@ -13,8 +13,9 @@ import { syncManager } from './services/sync-manager';
import { setPostgreSQLClient, setMongoDBClient } from './clients';
// Initialize configuration
await initializeConfig();
await initializeConfig('./config');
const serviceConfig = getServiceConfig();
const databaseConfig = getDatabaseConfig();
// Initialize logger with config
const loggingConfig = getLoggingConfig();
@ -191,16 +192,16 @@ async function initializeServices() {
try {
// Initialize MongoDB client
logger.info('Connecting to MongoDB...');
const mongoConfig = serviceConfig.database.mongodb;
const mongoConfig = databaseConfig.mongodb;
mongoClient = await createAndConnectMongoDBClient({
uri: mongoConfig.uri,
database: mongoConfig.database,
host: 'localhost',
port: 27017,
host: mongoConfig.host || 'localhost',
port: mongoConfig.port || 27017,
timeouts: {
connectTimeout: mongoConfig.connectionTimeout || 30000,
connectTimeout: 30000,
socketTimeout: 30000,
serverSelectionTimeout: mongoConfig.serverSelectionTimeout || 5000,
serverSelectionTimeout: 5000,
},
});
setMongoDBClient(mongoClient);
@ -208,17 +209,17 @@ async function initializeServices() {
// Initialize PostgreSQL client
logger.info('Connecting to PostgreSQL...');
const pgConfig = serviceConfig.database.postgres;
const pgConfig = databaseConfig.postgres;
postgresClient = await createAndConnectPostgreSQLClient({
host: pgConfig.host,
port: pgConfig.port,
database: pgConfig.database,
username: pgConfig.username,
username: pgConfig.user,
password: pgConfig.password,
poolSettings: {
min: 2,
max: pgConfig.maxConnections || 10,
idleTimeoutMillis: 30000,
max: pgConfig.poolSize || 10,
idleTimeoutMillis: pgConfig.idleTimeout || 30000,
},
});
setPostgreSQLClient(postgresClient);

View file

@ -11,49 +11,5 @@
"origin": ["http://localhost:4200", "http://localhost:3000", "http://localhost:3002"],
"credentials": true
}
},
"logging": {
"level": "info",
"format": "json"
},
"database": {
"postgres": {
"host": "localhost",
"port": 5432,
"database": "trading_bot",
"user": "trading_user",
"password": "trading_pass_dev",
"ssl": false,
"poolSize": 10,
"connectionTimeout": 30000,
"idleTimeout": 10000
},
"questdb": {
"host": "localhost",
"ilpPort": 9009,
"httpPort": 9000,
"pgPort": 8812,
"database": "questdb",
"user": "admin",
"password": "quest",
"bufferSize": 65536,
"flushInterval": 1000
},
"mongodb": {
"host": "localhost",
"port": 27017,
"database": "stock",
"user": "trading_admin",
"password": "trading_mongo_dev",
"authSource": "admin",
"poolSize": 10
},
"dragonfly": {
"host": "localhost",
"port": 6379,
"db": 0,
"maxRetries": 3,
"retryDelay": 100
}
}
}