work on qm and added disabled to operetions
This commit is contained in:
parent
2011c4c83f
commit
38bd15cad8
8 changed files with 67 additions and 181 deletions
|
|
@ -100,21 +100,46 @@ export class HandlerScanner {
|
|||
const operations = HandlerClass.__operations || [];
|
||||
const schedules = HandlerClass.__schedules || [];
|
||||
const isDisabled = HandlerClass.__disabled || false;
|
||||
const disabledOperations = HandlerClass.__disabledOperations || [];
|
||||
|
||||
if (isDisabled) {
|
||||
this.logger.debug('Skipping disabled handler', { handlerName });
|
||||
return;
|
||||
}
|
||||
|
||||
// Filter out disabled operations
|
||||
const enabledOperations = operations.filter((op: any) => {
|
||||
const isDisabled = disabledOperations.includes(op.method);
|
||||
if (isDisabled) {
|
||||
this.logger.debug('Skipping disabled operation', {
|
||||
handlerName,
|
||||
operation: op.name,
|
||||
method: op.method
|
||||
});
|
||||
}
|
||||
return !isDisabled;
|
||||
});
|
||||
|
||||
const enabledSchedules = schedules.filter((schedule: any) => {
|
||||
const isDisabled = disabledOperations.includes(schedule.operation);
|
||||
if (isDisabled) {
|
||||
this.logger.debug('Skipping disabled scheduled operation', {
|
||||
handlerName,
|
||||
operation: schedule.operation
|
||||
});
|
||||
}
|
||||
return !isDisabled;
|
||||
});
|
||||
|
||||
// Build metadata
|
||||
const metadata: HandlerMetadata = {
|
||||
name: handlerName,
|
||||
service: this.options.serviceName,
|
||||
operations: operations.map((op: any) => ({
|
||||
operations: enabledOperations.map((op: any) => ({
|
||||
name: op.name,
|
||||
method: op.method,
|
||||
})),
|
||||
schedules: schedules.map((schedule: any) => ({
|
||||
schedules: enabledSchedules.map((schedule: any) => ({
|
||||
operation: schedule.operation,
|
||||
cronPattern: schedule.cronPattern,
|
||||
priority: schedule.priority,
|
||||
|
|
@ -127,7 +152,7 @@ export class HandlerScanner {
|
|||
|
||||
// Build configuration with operation handlers
|
||||
const operationHandlers: Record<string, any> = {};
|
||||
for (const op of operations) {
|
||||
for (const op of enabledOperations) {
|
||||
operationHandlers[op.name] = async (payload: any) => {
|
||||
const handler = this.container.resolve<IHandler>(handlerName);
|
||||
const context: ExecutionContext = {
|
||||
|
|
@ -141,8 +166,8 @@ export class HandlerScanner {
|
|||
const configuration: HandlerConfiguration = {
|
||||
name: handlerName,
|
||||
operations: operationHandlers,
|
||||
scheduledJobs: schedules.map((schedule: any) => {
|
||||
const operation = operations.find((op: any) => op.method === schedule.operation);
|
||||
scheduledJobs: enabledSchedules.map((schedule: any) => {
|
||||
const operation = enabledOperations.find((op: any) => op.method === schedule.operation);
|
||||
return {
|
||||
type: `${handlerName}-${schedule.operation}`,
|
||||
operation: operation?.name || schedule.operation,
|
||||
|
|
@ -175,8 +200,9 @@ export class HandlerScanner {
|
|||
handlerName,
|
||||
exportName,
|
||||
filePath,
|
||||
operations: operations.length,
|
||||
schedules: schedules.length,
|
||||
operations: enabledOperations.length,
|
||||
schedules: enabledSchedules.length,
|
||||
disabledOperations: disabledOperations.length,
|
||||
service: this.options.serviceName,
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -87,15 +87,26 @@ export function QueueSchedule(
|
|||
}
|
||||
|
||||
/**
|
||||
* Disabled decorator - marks a handler as disabled for auto-registration
|
||||
* Handlers marked with @Disabled() will be skipped during auto-registration
|
||||
* Disabled decorator - marks a handler or operation as disabled
|
||||
* Can be used on:
|
||||
* - Classes: Entire handler will be skipped during auto-registration
|
||||
* - Methods: Individual operations will be skipped during registration
|
||||
*/
|
||||
export function Disabled() {
|
||||
return function <T extends { new (...args: any[]): {} }>(target: T, _context?: any) {
|
||||
// Store disabled flag on the constructor
|
||||
(target as any).__disabled = true;
|
||||
|
||||
return target;
|
||||
return function (target: any, propertyKey?: string, descriptor?: PropertyDescriptor): any {
|
||||
if (propertyKey) {
|
||||
// Method decorator - mark specific operation as disabled
|
||||
const constructor = target.constructor;
|
||||
if (!constructor.__disabledOperations) {
|
||||
constructor.__disabledOperations = [];
|
||||
}
|
||||
constructor.__disabledOperations.push(propertyKey);
|
||||
return descriptor;
|
||||
} else {
|
||||
// Class decorator - mark entire handler as disabled
|
||||
(target as any).__disabled = true;
|
||||
return target;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue