switching to generic queue lib

This commit is contained in:
Boki 2025-06-14 15:28:51 -04:00
parent 6c548416d1
commit e5170b1c78
15 changed files with 500 additions and 1086 deletions

View file

@ -3,7 +3,7 @@
*/
import { Hono } from 'hono';
import { getLogger } from '@stock-bot/logger';
import { queueManager } from '../services/queue.service';
import { queueManager } from '../services/queue-manager.service';
const logger = getLogger('market-data-routes');
@ -16,9 +16,8 @@ marketDataRoutes.get('/api/live/:symbol', async c => {
try {
// Queue job for live data using Yahoo provider
const job = await queueManager.addJob({
const job = await queueManager.addJob('market-data-live', {
type: 'market-data-live',
service: 'market-data',
provider: 'yahoo-finance',
operation: 'live-data',
payload: { symbol },
@ -47,9 +46,8 @@ marketDataRoutes.get('/api/historical/:symbol', async c => {
const toDate = to ? new Date(to) : new Date(); // Now
// Queue job for historical data using Yahoo provider
const job = await queueManager.addJob({
const job = await queueManager.addJob('market-data-historical', {
type: 'market-data-historical',
service: 'market-data',
provider: 'yahoo-finance',
operation: 'historical-data',
payload: {
@ -72,3 +70,50 @@ marketDataRoutes.get('/api/historical/:symbol', async c => {
return c.json({ status: 'error', message: 'Failed to queue historical data job' }, 500);
}
});
// Batch processing endpoint using new queue system
marketDataRoutes.post('/api/process-symbols', async c => {
try {
const {
symbols,
provider = 'ib',
operation = 'fetch-session',
useBatching = true,
totalDelayMs = 30000,
batchSize = 10,
} = await c.req.json();
if (!symbols || !Array.isArray(symbols) || symbols.length === 0) {
return c.json({ status: 'error', message: 'Invalid symbols array' }, 400);
}
logger.info('Batch processing symbols', {
count: symbols.length,
provider,
operation,
useBatching,
});
const result = await queueManager.processSymbols(symbols, {
totalDelayMs,
useBatching,
batchSize,
priority: 2,
provider,
operation,
retries: 2,
removeOnComplete: 5,
removeOnFail: 10,
});
return c.json({
status: 'success',
message: 'Batch processing initiated',
result,
symbols: symbols.length,
});
} catch (error) {
logger.error('Failed to process symbols batch', { error });
return c.json({ status: 'error', message: 'Failed to process symbols batch' }, 500);
}
});