moved handlers out of queue will be reused with event-bus
This commit is contained in:
parent
36cb84b343
commit
dc4bd7b18e
16 changed files with 145 additions and 295 deletions
|
|
@ -11,8 +11,7 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"@stock-bot/config": "workspace:*",
|
||||
"@stock-bot/logger": "workspace:*",
|
||||
"@stock-bot/di": "workspace:*"
|
||||
"@stock-bot/logger": "workspace:*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^20.11.0",
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
import type { ServiceContainer } from '@stock-bot/di';
|
||||
import { getLogger } from '@stock-bot/logger';
|
||||
import type { IHandler, ExecutionContext } from '../types/types';
|
||||
|
||||
|
|
@ -9,7 +8,7 @@ import type { IHandler, ExecutionContext } from '../types/types';
|
|||
export abstract class BaseHandler implements IHandler {
|
||||
protected readonly logger;
|
||||
|
||||
constructor(protected readonly container: ServiceContainer) {
|
||||
constructor(protected readonly container: any) {
|
||||
this.logger = getLogger(this.constructor.name);
|
||||
}
|
||||
|
||||
|
|
@ -23,7 +22,7 @@ export abstract class BaseHandler implements IHandler {
|
|||
* Queue helper methods
|
||||
*/
|
||||
protected async scheduleOperation(operation: string, payload: unknown, delay?: number): Promise<void> {
|
||||
const queue = await this.container.resolveAsync('queue');
|
||||
const queue = await this.container.resolveAsync('queue') as any;
|
||||
await queue.add(operation, payload, { delay });
|
||||
}
|
||||
|
||||
|
|
@ -31,7 +30,7 @@ export abstract class BaseHandler implements IHandler {
|
|||
* Get a service from the container
|
||||
*/
|
||||
protected async getService<T>(serviceName: string): Promise<T> {
|
||||
return await this.container.resolveAsync<T>(serviceName);
|
||||
return await this.container.resolveAsync(serviceName);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ export function Handler(name: string) {
|
|||
* @param name Operation name
|
||||
*/
|
||||
export function Operation(name: string) {
|
||||
return function (target: any, propertyName: string, descriptor: PropertyDescriptor) {
|
||||
return function (target: any, propertyName: string, descriptor?: PropertyDescriptor) {
|
||||
// Store operation metadata for future use
|
||||
if (!target.constructor.__operations) {
|
||||
target.constructor.__operations = [];
|
||||
|
|
@ -44,7 +44,7 @@ export function QueueSchedule(
|
|||
description?: string;
|
||||
}
|
||||
) {
|
||||
return function (target: any, propertyName: string, descriptor: PropertyDescriptor) {
|
||||
return function (target: any, propertyName: string, descriptor?: PropertyDescriptor) {
|
||||
// Store schedule metadata for future use
|
||||
if (!target.constructor.__schedules) {
|
||||
target.constructor.__schedules = [];
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
import type { ServiceContainer } from '@stock-bot/di';
|
||||
// import type { ServiceContainer } from '@stock-bot/di'; // Temporarily commented
|
||||
|
||||
// Simple execution context - mostly queue for now
|
||||
export interface ExecutionContext {
|
||||
type: 'queue'; // | 'event' - commented for future
|
||||
serviceContainer: ServiceContainer;
|
||||
serviceContainer: any; // ServiceContainer - temporarily any
|
||||
metadata: {
|
||||
source?: string;
|
||||
jobId?: string;
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@
|
|||
"include": ["src/**/*"],
|
||||
"references": [
|
||||
{ "path": "../config" },
|
||||
{ "path": "../logger" },
|
||||
{ "path": "../di" }
|
||||
{ "path": "../logger" }
|
||||
]
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue