From acf66dbfb6461c6e16de2ed5294190a251ab94c8 Mon Sep 17 00:00:00 2001 From: Boki Date: Sun, 22 Jun 2025 13:16:49 -0400 Subject: [PATCH] fixes --- .../src/handlers/ceo/ceo.handler.ts | 16 ++++++++++------ apps/data-ingestion/src/index.ts | 5 ++--- libs/data/mongodb/src/client.ts | 2 +- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/apps/data-ingestion/src/handlers/ceo/ceo.handler.ts b/apps/data-ingestion/src/handlers/ceo/ceo.handler.ts index beb156e..d6d039c 100644 --- a/apps/data-ingestion/src/handlers/ceo/ceo.handler.ts +++ b/apps/data-ingestion/src/handlers/ceo/ceo.handler.ts @@ -4,7 +4,7 @@ import { ScheduledOperation, type IServiceContainer } from '@stock-bot/handlers'; -import { fetch, getRandomUserAgent } from '@stock-bot/utils'; +import { getRandomUserAgent } from '@stock-bot/utils'; @Handler('ceo') export class CeoHandler extends BaseHandler { @@ -17,18 +17,22 @@ export class CeoHandler extends BaseHandler { immediately: true, description: 'Get all CEO symbols and exchanges' }) - async updateCeoChannels(payload: number | undefined): Promise { - const proxy = this.proxy.getProxy();; + async updateCeoChannels(payload: number | undefined, handler: BaseHandler): Promise { + const proxy = this.proxy?.getProxy(); + if(!proxy) { + this.logger.warn('No proxy available for CEO channels update'); + return; + } let page; if(payload === undefined) { page = 1 }else{ page = payload; } + this.logger.info(`Fetching CEO channels for page ${page} with proxy ${proxy}`); - const response = await fetch('https://api.ceo.ca/api/home?exchange=all&sort_by=symbol§or=All&tab=companies&page='+page, { - method: 'GET', + const response = await this.http.get('https://api.ceo.ca/api/home?exchange=all&sort_by=symbol§or=All&tab=companies&page='+page, { proxy: proxy, headers: { 'User-Agent': getRandomUserAgent() @@ -69,7 +73,7 @@ export class CeoHandler extends BaseHandler { if(page === 1) { for( let i = 2; i <= totalPages; i++) { - this.logger.info(`Scheduling next page ${i} for CEO channels`); + this.logger.info(`Scheduling page ${i} of ${totalPages} for CEO channels`); this.scheduleOperation('update-ceo-channels', i) } } diff --git a/apps/data-ingestion/src/index.ts b/apps/data-ingestion/src/index.ts index 4c41817..02df141 100644 --- a/apps/data-ingestion/src/index.ts +++ b/apps/data-ingestion/src/index.ts @@ -114,10 +114,9 @@ async function initializeServices() { logger.debug('Initializing data handlers with Awilix DI pattern...'); // Auto-register all handlers with the service container from Awilix - // TODO: Fix handler registration - // await initializeAllHandlers(serviceContainer); + await initializeAllHandlers(serviceContainer); - logger.info('Data handlers initialization skipped for testing'); + logger.info('Data handlers initialized with new DI pattern'); // Create scheduled jobs from registered handlers logger.debug('Creating scheduled jobs from registered handlers...'); diff --git a/libs/data/mongodb/src/client.ts b/libs/data/mongodb/src/client.ts index bf99898..dbd2863 100644 --- a/libs/data/mongodb/src/client.ts +++ b/libs/data/mongodb/src/client.ts @@ -1,6 +1,6 @@ import type { Logger } from '@stock-bot/core/logger'; -import { Collection, Db, MongoClient } from 'mongodb'; import type { OptionalUnlessRequiredId } from 'mongodb'; +import { Collection, Db, MongoClient } from 'mongodb'; import type { ConnectionEvents, DocumentBase, DynamicPoolConfig, MongoDBClientConfig, PoolMetrics } from './types'; /**