added initial batch decorator and fixed payload - still need to test batching

This commit is contained in:
Boki 2025-06-24 23:15:43 -04:00
parent 44c087aaae
commit eff529a6ca
5 changed files with 57 additions and 6 deletions

View file

@ -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;

View file

@ -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
};
}),
};

View file

@ -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
};
});

View file

@ -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;
};

View file

@ -39,6 +39,13 @@ export interface ScheduledJob<T = unknown> {
description?: string;
immediately?: boolean;
delay?: number;
batch?: {
enabled?: boolean;
size?: number;
delayInHours?: number;
priority?: number;
direct?: boolean;
};
}
// Handler configuration