added new queue lib with batch processor and provider
This commit is contained in:
parent
ddcf94a587
commit
6c548416d1
19 changed files with 1939 additions and 35 deletions
|
|
@ -38,7 +38,7 @@ async function initializeServices() {
|
|||
// - Event bus for listening to data events
|
||||
// - Technical indicators engines
|
||||
// - Vector engines for similarity calculations
|
||||
|
||||
|
||||
logger.info('All services initialized successfully');
|
||||
} catch (error) {
|
||||
logger.error('Failed to initialize services', { error });
|
||||
|
|
@ -49,14 +49,14 @@ async function initializeServices() {
|
|||
// Start server
|
||||
async function startServer() {
|
||||
await initializeServices();
|
||||
|
||||
|
||||
// Start the HTTP server using Bun's native serve
|
||||
server = Bun.serve({
|
||||
port: PORT,
|
||||
fetch: app.fetch,
|
||||
development: process.env.NODE_ENV === 'development',
|
||||
});
|
||||
|
||||
|
||||
logger.info(`Processing Service started on port ${PORT}`);
|
||||
}
|
||||
|
||||
|
|
@ -94,7 +94,7 @@ shutdown.onShutdown(async () => {
|
|||
});
|
||||
|
||||
// Handle uncaught exceptions and unhandled rejections
|
||||
process.on('uncaughtException', (error) => {
|
||||
process.on('uncaughtException', error => {
|
||||
logger.error('Uncaught exception', { error });
|
||||
shutdown.shutdownAndExit('uncaughtException', 1);
|
||||
});
|
||||
|
|
@ -116,7 +116,7 @@ process.on('SIGTERM', () => {
|
|||
});
|
||||
|
||||
// Start the service
|
||||
startServer().catch((error) => {
|
||||
startServer().catch(error => {
|
||||
logger.error('Failed to start processing service', { error });
|
||||
process.exit(1);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -6,38 +6,38 @@ import { Hono } from 'hono';
|
|||
const healthRoutes = new Hono();
|
||||
|
||||
// Health check endpoint
|
||||
healthRoutes.get('/health', (c) => {
|
||||
healthRoutes.get('/health', c => {
|
||||
return c.json({
|
||||
status: 'healthy',
|
||||
service: 'processing-service',
|
||||
timestamp: new Date().toISOString(),
|
||||
version: '1.0.0'
|
||||
version: '1.0.0',
|
||||
});
|
||||
});
|
||||
|
||||
// Detailed status endpoint
|
||||
healthRoutes.get('/status', (c) => {
|
||||
healthRoutes.get('/status', c => {
|
||||
return c.json({
|
||||
service: 'processing-service',
|
||||
status: 'running',
|
||||
uptime: process.uptime(),
|
||||
memory: process.memoryUsage(),
|
||||
timestamp: new Date().toISOString(),
|
||||
environment: process.env.NODE_ENV || 'development'
|
||||
environment: process.env.NODE_ENV || 'development',
|
||||
});
|
||||
});
|
||||
|
||||
// Ready check endpoint
|
||||
healthRoutes.get('/ready', (c) => {
|
||||
healthRoutes.get('/ready', c => {
|
||||
// TODO: Add checks for service dependencies
|
||||
// - Database connections
|
||||
// - Event bus connections
|
||||
// - Required resources
|
||||
|
||||
|
||||
return c.json({
|
||||
status: 'ready',
|
||||
service: 'processing-service',
|
||||
timestamp: new Date().toISOString()
|
||||
timestamp: new Date().toISOString(),
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -9,40 +9,42 @@ const processingRoutes = new Hono();
|
|||
const logger = getLogger('processing-routes');
|
||||
|
||||
// Process data endpoint
|
||||
processingRoutes.post('/process', async (c) => {
|
||||
processingRoutes.post('/process', async c => {
|
||||
try {
|
||||
const body = await c.req.json();
|
||||
|
||||
logger.info('Processing request received', {
|
||||
|
||||
logger.info('Processing request received', {
|
||||
dataType: body.type,
|
||||
recordCount: body.data?.length || 0
|
||||
recordCount: body.data?.length || 0,
|
||||
});
|
||||
|
||||
|
||||
// Use processing service manager to handle the request
|
||||
const result = await processingServiceManager.processData(
|
||||
body.type || 'unknown',
|
||||
body.data || []
|
||||
);
|
||||
|
||||
|
||||
return c.json({
|
||||
status: 'success',
|
||||
message: 'Data processing completed',
|
||||
result,
|
||||
timestamp: new Date().toISOString()
|
||||
timestamp: new Date().toISOString(),
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
logger.error('Processing error', { error });
|
||||
return c.json({
|
||||
status: 'error',
|
||||
message: 'Processing failed',
|
||||
error: error instanceof Error ? error.message : 'Unknown error'
|
||||
}, 500);
|
||||
return c.json(
|
||||
{
|
||||
status: 'error',
|
||||
message: 'Processing failed',
|
||||
error: error instanceof Error ? error.message : 'Unknown error',
|
||||
},
|
||||
500
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
// Get processing status
|
||||
processingRoutes.get('/status', (c) => {
|
||||
processingRoutes.get('/status', c => {
|
||||
const status = processingServiceManager.getStatus();
|
||||
return c.json({
|
||||
...status,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
* Processing Service Manager
|
||||
*
|
||||
*
|
||||
* Manages the core processing operations for the processing service
|
||||
*/
|
||||
import { getLogger } from '@stock-bot/logger';
|
||||
|
|
@ -24,7 +24,7 @@ export class ProcessingServiceManager {
|
|||
// - Data transformation pipeline
|
||||
// - Event listeners for data events
|
||||
// - Job queues for processing tasks
|
||||
|
||||
|
||||
this.isInitialized = true;
|
||||
logger.info('Processing service manager initialized successfully');
|
||||
} catch (error) {
|
||||
|
|
@ -46,7 +46,7 @@ export class ProcessingServiceManager {
|
|||
// - Stop job processing
|
||||
// - Close database connections
|
||||
// - Cleanup event listeners
|
||||
|
||||
|
||||
this.isInitialized = false;
|
||||
logger.info('Processing service manager shut down successfully');
|
||||
} catch (error) {
|
||||
|
|
@ -58,7 +58,10 @@ export class ProcessingServiceManager {
|
|||
/**
|
||||
* Process data with technical indicators
|
||||
*/
|
||||
async processData(dataType: string, data: unknown[]): Promise<{
|
||||
async processData(
|
||||
dataType: string,
|
||||
data: unknown[]
|
||||
): Promise<{
|
||||
status: string;
|
||||
dataType: string;
|
||||
inputCount: number;
|
||||
|
|
@ -78,19 +81,18 @@ export class ProcessingServiceManager {
|
|||
// - Calculate signals
|
||||
// - Transform data format
|
||||
// - Save processed results
|
||||
|
||||
|
||||
const result = {
|
||||
status: 'success',
|
||||
dataType,
|
||||
inputCount: data.length,
|
||||
outputCount: data.length, // Placeholder
|
||||
processedAt: new Date(),
|
||||
processingTime: 0 // Placeholder
|
||||
processingTime: 0, // Placeholder
|
||||
};
|
||||
|
||||
logger.info('Data processing completed', result);
|
||||
return result;
|
||||
|
||||
} catch (error) {
|
||||
logger.error('Data processing failed', { error, dataType, inputCount: data.length });
|
||||
throw error;
|
||||
|
|
@ -104,7 +106,7 @@ export class ProcessingServiceManager {
|
|||
return {
|
||||
initialized: this.isInitialized,
|
||||
status: this.isInitialized ? 'ready' : 'not_initialized',
|
||||
timestamp: new Date().toISOString()
|
||||
timestamp: new Date().toISOString(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue