started refactor of data-sync-service
This commit is contained in:
parent
67833a2fd7
commit
3ae9de8376
27 changed files with 1754 additions and 1465 deletions
|
|
@ -1,7 +1,6 @@
|
|||
import { Hono } from 'hono';
|
||||
import { getLogger } from '@stock-bot/logger';
|
||||
import { syncManager } from '../services/sync-manager';
|
||||
import { enhancedSyncManager } from '../services/enhanced-sync-manager';
|
||||
import { QueueManager } from '@stock-bot/queue';
|
||||
|
||||
const logger = getLogger('sync-routes');
|
||||
const sync = new Hono();
|
||||
|
|
@ -9,10 +8,18 @@ const sync = new Hono();
|
|||
// Manual sync trigger endpoints
|
||||
sync.post('/symbols', async c => {
|
||||
try {
|
||||
const result = await syncManager.syncQMSymbols();
|
||||
return c.json({ success: true, result });
|
||||
const queueManager = QueueManager.getInstance();
|
||||
const symbolsQueue = queueManager.getQueue('symbols');
|
||||
|
||||
const job = await symbolsQueue.addJob('sync-qm-symbols', {
|
||||
handler: 'symbols',
|
||||
operation: 'sync-qm-symbols',
|
||||
payload: {},
|
||||
});
|
||||
|
||||
return c.json({ success: true, jobId: job.id, message: 'QM symbols sync job queued' });
|
||||
} catch (error) {
|
||||
logger.error('Manual symbol sync failed', { error });
|
||||
logger.error('Failed to queue symbol sync job', { error });
|
||||
return c.json(
|
||||
{ success: false, error: error instanceof Error ? error.message : 'Unknown error' },
|
||||
500
|
||||
|
|
@ -22,10 +29,18 @@ sync.post('/symbols', async c => {
|
|||
|
||||
sync.post('/exchanges', async c => {
|
||||
try {
|
||||
const result = await syncManager.syncQMExchanges();
|
||||
return c.json({ success: true, result });
|
||||
const queueManager = QueueManager.getInstance();
|
||||
const exchangesQueue = queueManager.getQueue('exchanges');
|
||||
|
||||
const job = await exchangesQueue.addJob('sync-qm-exchanges', {
|
||||
handler: 'exchanges',
|
||||
operation: 'sync-qm-exchanges',
|
||||
payload: {},
|
||||
});
|
||||
|
||||
return c.json({ success: true, jobId: job.id, message: 'QM exchanges sync job queued' });
|
||||
} catch (error) {
|
||||
logger.error('Manual exchange sync failed', { error });
|
||||
logger.error('Failed to queue exchange sync job', { error });
|
||||
return c.json(
|
||||
{ success: false, error: error instanceof Error ? error.message : 'Unknown error' },
|
||||
500
|
||||
|
|
@ -36,8 +51,18 @@ sync.post('/exchanges', async c => {
|
|||
// Get sync status
|
||||
sync.get('/status', async c => {
|
||||
try {
|
||||
const status = await syncManager.getSyncStatus();
|
||||
return c.json(status);
|
||||
const queueManager = QueueManager.getInstance();
|
||||
const symbolsQueue = queueManager.getQueue('symbols');
|
||||
|
||||
const job = await symbolsQueue.addJob('sync-status', {
|
||||
handler: 'symbols',
|
||||
operation: 'sync-status',
|
||||
payload: {},
|
||||
});
|
||||
|
||||
// Wait for job to complete and return result
|
||||
const result = await job.waitUntilFinished();
|
||||
return c.json(result);
|
||||
} catch (error) {
|
||||
logger.error('Failed to get sync status', { error });
|
||||
return c.json({ error: error instanceof Error ? error.message : 'Unknown error' }, 500);
|
||||
|
|
@ -47,10 +72,20 @@ sync.get('/status', async c => {
|
|||
// Clear data endpoint
|
||||
sync.post('/clear', async c => {
|
||||
try {
|
||||
const result = await enhancedSyncManager.clearPostgreSQLData();
|
||||
const queueManager = QueueManager.getInstance();
|
||||
const exchangesQueue = queueManager.getQueue('exchanges');
|
||||
|
||||
const job = await exchangesQueue.addJob('clear-postgresql-data', {
|
||||
handler: 'exchanges',
|
||||
operation: 'clear-postgresql-data',
|
||||
payload: {},
|
||||
});
|
||||
|
||||
// Wait for job to complete and return result
|
||||
const result = await job.waitUntilFinished();
|
||||
return c.json({ success: true, result });
|
||||
} catch (error) {
|
||||
logger.error('Clear PostgreSQL data failed', { error });
|
||||
logger.error('Failed to clear PostgreSQL data', { error });
|
||||
return c.json(
|
||||
{ success: false, error: error instanceof Error ? error.message : 'Unknown error' },
|
||||
500
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue