added initial batch decorator and fixed payload - still need to test batching
This commit is contained in:
parent
44c087aaae
commit
eff529a6ca
5 changed files with 57 additions and 6 deletions
|
|
@ -26,7 +26,12 @@ export class CeoHandler extends BaseHandler {
|
||||||
priority: 5,
|
priority: 5,
|
||||||
immediately: false,
|
immediately: false,
|
||||||
description: 'Process unique CEO symbols and schedule individual jobs',
|
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;
|
updateUniqueSymbolsPosts = updateUniqueSymbols;
|
||||||
|
|
||||||
|
|
@ -35,9 +40,15 @@ export class CeoHandler extends BaseHandler {
|
||||||
priority: 5,
|
priority: 5,
|
||||||
immediately: false,
|
immediately: false,
|
||||||
description: 'Process unique CEO symbols and schedule individual jobs',
|
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')
|
@Operation('get-posts')
|
||||||
getPosts = getPosts;
|
getPosts = getPosts;
|
||||||
|
|
|
||||||
|
|
@ -119,6 +119,8 @@ export class HandlerScanner {
|
||||||
priority: schedule.priority,
|
priority: schedule.priority,
|
||||||
immediately: schedule.immediately,
|
immediately: schedule.immediately,
|
||||||
description: schedule.description,
|
description: schedule.description,
|
||||||
|
payload: schedule.payload,
|
||||||
|
batch: schedule.batch,
|
||||||
})),
|
})),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -147,6 +149,8 @@ export class HandlerScanner {
|
||||||
priority: schedule.priority || 5,
|
priority: schedule.priority || 5,
|
||||||
immediately: schedule.immediately || false,
|
immediately: schedule.immediately || false,
|
||||||
description: schedule.description || `${handlerName} ${schedule.operation}`,
|
description: schedule.description || `${handlerName} ${schedule.operation}`,
|
||||||
|
payload: schedule.payload, // Include payload from decorator
|
||||||
|
batch: schedule.batch, // Include batch config from decorator
|
||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -354,6 +354,8 @@ export abstract class BaseHandler implements IHandler {
|
||||||
priority: schedule.priority || 5,
|
priority: schedule.priority || 5,
|
||||||
immediately: schedule.immediately || false,
|
immediately: schedule.immediately || false,
|
||||||
description: schedule.description || `${handlerName} ${schedule.operation}`,
|
description: schedule.description || `${handlerName} ${schedule.operation}`,
|
||||||
|
payload: schedule.payload, // Include payload from decorator
|
||||||
|
batch: schedule.batch, // Include batch config from decorator
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,20 @@ export function Handler(name: string) {
|
||||||
/**
|
/**
|
||||||
* Operation decorator - marks a method as an operation
|
* Operation decorator - marks a method as an operation
|
||||||
* @param name Operation name
|
* @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 {
|
return function (target: any, methodName: string, descriptor?: PropertyDescriptor): any {
|
||||||
// Store metadata directly on the class constructor
|
// Store metadata directly on the class constructor
|
||||||
const constructor = target.constructor;
|
const constructor = target.constructor;
|
||||||
|
|
@ -29,6 +41,7 @@ export function Operation(name: string): any {
|
||||||
constructor.__operations.push({
|
constructor.__operations.push({
|
||||||
name,
|
name,
|
||||||
method: methodName,
|
method: methodName,
|
||||||
|
batch: options?.batch,
|
||||||
});
|
});
|
||||||
|
|
||||||
return descriptor;
|
return descriptor;
|
||||||
|
|
@ -47,6 +60,13 @@ export function QueueSchedule(
|
||||||
immediately?: boolean;
|
immediately?: boolean;
|
||||||
description?: string;
|
description?: string;
|
||||||
payload?: any;
|
payload?: any;
|
||||||
|
batch?: {
|
||||||
|
enabled?: boolean;
|
||||||
|
size?: number;
|
||||||
|
delayInHours?: number;
|
||||||
|
priority?: number;
|
||||||
|
direct?: boolean;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
): any {
|
): any {
|
||||||
return function (target: any, methodName: string, descriptor?: PropertyDescriptor): any {
|
return function (target: any, methodName: string, descriptor?: PropertyDescriptor): any {
|
||||||
|
|
@ -94,11 +114,18 @@ export function ScheduledOperation(
|
||||||
immediately?: boolean;
|
immediately?: boolean;
|
||||||
description?: string;
|
description?: string;
|
||||||
payload?: any;
|
payload?: any;
|
||||||
|
batch?: {
|
||||||
|
enabled?: boolean;
|
||||||
|
size?: number;
|
||||||
|
delayInHours?: number;
|
||||||
|
priority?: number;
|
||||||
|
direct?: boolean;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
): any {
|
): any {
|
||||||
return function (target: any, methodName: string, descriptor?: PropertyDescriptor): any {
|
return function (target: any, methodName: string, descriptor?: PropertyDescriptor): any {
|
||||||
// Apply both decorators
|
// Apply both decorators with batch configuration
|
||||||
Operation(name)(target, methodName, descriptor);
|
Operation(name, { batch: options?.batch })(target, methodName, descriptor);
|
||||||
QueueSchedule(cronPattern, options)(target, methodName, descriptor);
|
QueueSchedule(cronPattern, options)(target, methodName, descriptor);
|
||||||
return descriptor;
|
return descriptor;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,13 @@ export interface ScheduledJob<T = unknown> {
|
||||||
description?: string;
|
description?: string;
|
||||||
immediately?: boolean;
|
immediately?: boolean;
|
||||||
delay?: number;
|
delay?: number;
|
||||||
|
batch?: {
|
||||||
|
enabled?: boolean;
|
||||||
|
size?: number;
|
||||||
|
delayInHours?: number;
|
||||||
|
priority?: number;
|
||||||
|
direct?: boolean;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handler configuration
|
// Handler configuration
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue