diff --git a/apps/stock/data-ingestion/src/handlers/ceo/ceo.handler.ts b/apps/stock/data-ingestion/src/handlers/ceo/ceo.handler.ts index c0c2dd8..3900cd6 100644 --- a/apps/stock/data-ingestion/src/handlers/ceo/ceo.handler.ts +++ b/apps/stock/data-ingestion/src/handlers/ceo/ceo.handler.ts @@ -26,7 +26,12 @@ export class CeoHandler extends BaseHandler { priority: 5, immediately: false, description: 'Process unique CEO symbols and schedule individual jobs', - payload: { action: 'get-posts' } + payload: { action: 'get-posts' }, + batch: { + size: 100, + delayInHours: 1, + priority: 10, + } }) updateUniqueSymbolsPosts = updateUniqueSymbols; @@ -35,9 +40,15 @@ export class CeoHandler extends BaseHandler { priority: 5, immediately: false, description: 'Process unique CEO symbols and schedule individual jobs', - payload: { action: 'get-posts' } + payload: { action: 'get-shorts' }, + batch: { + size: 50, + delayInHours: 2, + priority: 8, + direct: true, // Use direct mode for shorts + } }) - updateUniqueSymbolsShots = updateUniqueSymbols; + updateUniqueSymbolsShorts = updateUniqueSymbols; @Operation('get-posts') getPosts = getPosts; diff --git a/libs/core/di/src/scanner/handler-scanner.ts b/libs/core/di/src/scanner/handler-scanner.ts index 696705a..0fb7096 100644 --- a/libs/core/di/src/scanner/handler-scanner.ts +++ b/libs/core/di/src/scanner/handler-scanner.ts @@ -119,6 +119,8 @@ export class HandlerScanner { priority: schedule.priority, immediately: schedule.immediately, description: schedule.description, + payload: schedule.payload, + batch: schedule.batch, })), }; @@ -147,6 +149,8 @@ export class HandlerScanner { priority: schedule.priority || 5, immediately: schedule.immediately || false, description: schedule.description || `${handlerName} ${schedule.operation}`, + payload: schedule.payload, // Include payload from decorator + batch: schedule.batch, // Include batch config from decorator }; }), }; diff --git a/libs/core/handlers/src/base/BaseHandler.ts b/libs/core/handlers/src/base/BaseHandler.ts index d38be9b..330665e 100644 --- a/libs/core/handlers/src/base/BaseHandler.ts +++ b/libs/core/handlers/src/base/BaseHandler.ts @@ -354,6 +354,8 @@ export abstract class BaseHandler implements IHandler { priority: schedule.priority || 5, immediately: schedule.immediately || false, description: schedule.description || `${handlerName} ${schedule.operation}`, + payload: schedule.payload, // Include payload from decorator + batch: schedule.batch, // Include batch config from decorator }; }); diff --git a/libs/core/handlers/src/decorators/decorators.ts b/libs/core/handlers/src/decorators/decorators.ts index 60985c7..5ff15cd 100644 --- a/libs/core/handlers/src/decorators/decorators.ts +++ b/libs/core/handlers/src/decorators/decorators.ts @@ -17,8 +17,20 @@ export function Handler(name: string) { /** * Operation decorator - marks a method as an operation * @param name Operation name + * @param options Optional configuration including batch settings */ -export function Operation(name: string): any { +export function Operation( + name: string, + options?: { + batch?: { + enabled?: boolean; + size?: number; + delayInHours?: number; + priority?: number; + direct?: boolean; + }; + } +): any { return function (target: any, methodName: string, descriptor?: PropertyDescriptor): any { // Store metadata directly on the class constructor const constructor = target.constructor; @@ -29,6 +41,7 @@ export function Operation(name: string): any { constructor.__operations.push({ name, method: methodName, + batch: options?.batch, }); return descriptor; @@ -47,6 +60,13 @@ export function QueueSchedule( immediately?: boolean; description?: string; payload?: any; + batch?: { + enabled?: boolean; + size?: number; + delayInHours?: number; + priority?: number; + direct?: boolean; + }; } ): any { return function (target: any, methodName: string, descriptor?: PropertyDescriptor): any { @@ -94,11 +114,18 @@ export function ScheduledOperation( immediately?: boolean; description?: string; payload?: any; + batch?: { + enabled?: boolean; + size?: number; + delayInHours?: number; + priority?: number; + direct?: boolean; + }; } ): any { return function (target: any, methodName: string, descriptor?: PropertyDescriptor): any { - // Apply both decorators - Operation(name)(target, methodName, descriptor); + // Apply both decorators with batch configuration + Operation(name, { batch: options?.batch })(target, methodName, descriptor); QueueSchedule(cronPattern, options)(target, methodName, descriptor); return descriptor; }; diff --git a/libs/core/types/src/handlers.ts b/libs/core/types/src/handlers.ts index ed6c16f..c0ad7ac 100644 --- a/libs/core/types/src/handlers.ts +++ b/libs/core/types/src/handlers.ts @@ -39,6 +39,13 @@ export interface ScheduledJob { description?: string; immediately?: boolean; delay?: number; + batch?: { + enabled?: boolean; + size?: number; + delayInHours?: number; + priority?: number; + direct?: boolean; + }; } // Handler configuration