work on ceo initial symbol and exchanges - pretty much done

This commit is contained in:
Boki 2025-06-22 12:09:03 -04:00
parent 7abc446671
commit fabf42dc7f
3 changed files with 12 additions and 5 deletions

View file

@ -2,23 +2,22 @@ import {
BaseHandler, BaseHandler,
Handler, Handler,
ScheduledOperation, ScheduledOperation,
type ExecutionContext,
type IServiceContainer type IServiceContainer
} from '@stock-bot/handlers'; } from '@stock-bot/handlers';
import { fetch, getRandomUserAgent } from '@stock-bot/utils'; import { fetch, getRandomUserAgent } from '@stock-bot/utils';
@Handler('qm') @Handler('ceo')
export class CeoHandler extends BaseHandler { export class CeoHandler extends BaseHandler {
constructor(services: IServiceContainer) { constructor(services: IServiceContainer) {
super(services); // Handler name read from @Handler decorator super(services); // Handler name read from @Handler decorator
} }
@ScheduledOperation('ceo', '0 */15 * * *', { @ScheduledOperation('update-ceo-channels', '0 */15 * * *', {
priority: 7, priority: 7,
immediately: true, immediately: true,
description: 'Get all CEO symbols and exchanges' description: 'Get all CEO symbols and exchanges'
}) })
async searchCeoChannels(payload: number | undefined, context: ExecutionContext): Promise<unknown> { async updateCeoChannels(payload: number | undefined): Promise<unknown> {
const proxy = this.proxy.getProxy();; const proxy = this.proxy.getProxy();;
let page; let page;
if(payload === undefined) { if(payload === undefined) {
@ -68,6 +67,13 @@ export class CeoHandler extends BaseHandler {
await this.mongodb.batchUpsert('ceoSymbols', symbols, ['symbol', 'exchange']); await this.mongodb.batchUpsert('ceoSymbols', symbols, ['symbol', 'exchange']);
await this.mongodb.batchUpsert('ceoExchanges', exchanges, ['exchange']); await this.mongodb.batchUpsert('ceoExchanges', exchanges, ['exchange']);
if(page === 1) {
for( let i = 2; i <= totalPages; i++) {
this.logger.info(`Scheduling next page ${i} for CEO channels`);
this.scheduleOperation('update-ceo-channels', i)
}
}
this.logger.info(`Fetched CEO channels for page ${page}/${totalPages}`); this.logger.info(`Fetched CEO channels for page ${page}/${totalPages}`);
return { page, totalPages }; return { page, totalPages };
} }

View file

@ -63,7 +63,7 @@ export async function fetch(
async function performFetch( async function performFetch(
input: RequestInfo | URL, input: RequestInfo | URL,
requestOptions: RequestInit, requestOptions: RequestInit,
logger: Logger, logger: any,
url: string url: string
): Promise<Response> { ): Promise<Response> {
logger.debug('HTTP request', { logger.debug('HTTP request', {

View file

@ -1,6 +1,7 @@
{ {
"$schema": "https://json.schemastore.org/tsconfig", "$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": { "compilerOptions": {
"types": ["bun-types"],
// JavaScript output target version // JavaScript output target version
"target": "ES2022", "target": "ES2022",
// Module configuration for different project types // Module configuration for different project types