added schedule job to have all params not just delay
This commit is contained in:
parent
3ac274705e
commit
4632c174dc
3 changed files with 37 additions and 5 deletions
|
|
@ -92,7 +92,7 @@ export class QMHandler extends BaseHandler {
|
||||||
// this.logger.debug('Spider job stored in cache', { spiderJobId, ttl: 3600 });
|
// this.logger.debug('Spider job stored in cache', { spiderJobId, ttl: 3600 });
|
||||||
|
|
||||||
// // Schedule follow-up processing if needed
|
// // Schedule follow-up processing if needed
|
||||||
// await this.scheduleOperation('search-symbols', { source: 'spider', spiderJobId }, 5000);
|
// await this.scheduleOperation('search-symbols', { source: 'spider', spiderJobId }, { delay: 5000 });
|
||||||
|
|
||||||
// return {
|
// return {
|
||||||
// success: true,
|
// success: true,
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,28 @@ import { createNamespacedCache } from '@stock-bot/cache';
|
||||||
import type { IServiceContainer } from '../types/service-container';
|
import type { IServiceContainer } from '../types/service-container';
|
||||||
import type { ExecutionContext, IHandler } from '../types/types';
|
import type { ExecutionContext, IHandler } from '../types/types';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Job scheduling options
|
||||||
|
*/
|
||||||
|
export interface JobScheduleOptions {
|
||||||
|
delay?: number;
|
||||||
|
priority?: number;
|
||||||
|
attempts?: number;
|
||||||
|
removeOnComplete?: number;
|
||||||
|
removeOnFail?: number;
|
||||||
|
backoff?: {
|
||||||
|
type: 'exponential' | 'fixed';
|
||||||
|
delay: number;
|
||||||
|
};
|
||||||
|
repeat?: {
|
||||||
|
pattern?: string;
|
||||||
|
key?: string;
|
||||||
|
limit?: number;
|
||||||
|
every?: number;
|
||||||
|
immediately?: boolean;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract base class for all handlers with improved DI
|
* Abstract base class for all handlers with improved DI
|
||||||
* Provides common functionality and structure for queue/event operations
|
* Provides common functionality and structure for queue/event operations
|
||||||
|
|
@ -83,7 +105,11 @@ export abstract class BaseHandler implements IHandler {
|
||||||
return await method.call(this, input, context);
|
return await method.call(this, input, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
async scheduleOperation(operation: string, payload: unknown, delay?: number): Promise<void> {
|
async scheduleOperation(
|
||||||
|
operation: string,
|
||||||
|
payload: unknown,
|
||||||
|
options?: JobScheduleOptions
|
||||||
|
): Promise<void> {
|
||||||
if (!this.queue) {
|
if (!this.queue) {
|
||||||
throw new Error('Queue service is not available');
|
throw new Error('Queue service is not available');
|
||||||
}
|
}
|
||||||
|
|
@ -93,7 +119,8 @@ export abstract class BaseHandler implements IHandler {
|
||||||
operation,
|
operation,
|
||||||
payload,
|
payload,
|
||||||
};
|
};
|
||||||
await queue.add(operation, jobData, { delay });
|
|
||||||
|
await queue.add(operation, jobData, options || {});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -171,9 +198,13 @@ export abstract class BaseHandler implements IHandler {
|
||||||
protected async scheduleIn(
|
protected async scheduleIn(
|
||||||
operation: string,
|
operation: string,
|
||||||
payload: unknown,
|
payload: unknown,
|
||||||
delaySeconds: number
|
delaySeconds: number,
|
||||||
|
additionalOptions?: Omit<JobScheduleOptions, 'delay'>
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
return this.scheduleOperation(operation, payload, delaySeconds * 1000);
|
return this.scheduleOperation(operation, payload, {
|
||||||
|
delay: delaySeconds * 1000,
|
||||||
|
...additionalOptions
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
// Base handler classes
|
// Base handler classes
|
||||||
export { BaseHandler, ScheduledHandler } from './base/BaseHandler';
|
export { BaseHandler, ScheduledHandler } from './base/BaseHandler';
|
||||||
|
export type { JobScheduleOptions } from './base/BaseHandler';
|
||||||
|
|
||||||
// Handler registry (re-exported from types to avoid circular deps)
|
// Handler registry (re-exported from types to avoid circular deps)
|
||||||
export { handlerRegistry } from '@stock-bot/types';
|
export { handlerRegistry } from '@stock-bot/types';
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue