work on ceo initial symbol and exchanges - pretty much done
This commit is contained in:
parent
7abc446671
commit
fabf42dc7f
3 changed files with 12 additions and 5 deletions
|
|
@ -2,23 +2,22 @@ import {
|
|||
BaseHandler,
|
||||
Handler,
|
||||
ScheduledOperation,
|
||||
type ExecutionContext,
|
||||
type IServiceContainer
|
||||
} from '@stock-bot/handlers';
|
||||
import { fetch, getRandomUserAgent } from '@stock-bot/utils';
|
||||
|
||||
@Handler('qm')
|
||||
@Handler('ceo')
|
||||
export class CeoHandler extends BaseHandler {
|
||||
constructor(services: IServiceContainer) {
|
||||
super(services); // Handler name read from @Handler decorator
|
||||
}
|
||||
|
||||
@ScheduledOperation('ceo', '0 */15 * * *', {
|
||||
@ScheduledOperation('update-ceo-channels', '0 */15 * * *', {
|
||||
priority: 7,
|
||||
immediately: true,
|
||||
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();;
|
||||
let page;
|
||||
if(payload === undefined) {
|
||||
|
|
@ -68,6 +67,13 @@ export class CeoHandler extends BaseHandler {
|
|||
await this.mongodb.batchUpsert('ceoSymbols', symbols, ['symbol', '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}`);
|
||||
return { page, totalPages };
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ export async function fetch(
|
|||
async function performFetch(
|
||||
input: RequestInfo | URL,
|
||||
requestOptions: RequestInit,
|
||||
logger: Logger,
|
||||
logger: any,
|
||||
url: string
|
||||
): Promise<Response> {
|
||||
logger.debug('HTTP request', {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
{
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"compilerOptions": {
|
||||
"types": ["bun-types"],
|
||||
// JavaScript output target version
|
||||
"target": "ES2022",
|
||||
// Module configuration for different project types
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue