Skip to content

Commit

Permalink
refactor: delete memory checker
Browse files Browse the repository at this point in the history
  • Loading branch information
OsirisAnubiz committed Oct 8, 2024
1 parent bab6109 commit 236c771
Show file tree
Hide file tree
Showing 9 changed files with 18 additions and 127 deletions.
1 change: 0 additions & 1 deletion packages/nestjs-batch-queue/src/checkers/index.ts

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import type { Type } from '@nestjs/common'
import type { ModuleMetadata } from '@nestjs/common'
import type { Type } from '@nestjs/common'
import type { ModuleMetadata } from '@nestjs/common'

import type { BatchQueueOptions } from '../batch-queue/index.js'
import type { Consumer } from '../batch-queue/index.js'
import type { MemoryCheckerOptions } from '../checkers/index.js'
import type { BatchQueueOptions } from '../batch-queue/index.js'
import type { Consumer } from '../batch-queue/index.js'

export interface BatchQueueModuleOptions {
core: BatchQueueOptions
memoryCheckerOptions?: MemoryCheckerOptions
}

export interface BatchQueueOptionsFactory {
Expand Down
32 changes: 14 additions & 18 deletions packages/nestjs-batch-queue/src/module/batch-queue.module.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,27 @@
import type { DynamicModule } from '@nestjs/common'
import type { Provider } from '@nestjs/common'
import type { DynamicModule } from '@nestjs/common'
import type { Provider } from '@nestjs/common'

import type { BatchQueueModuleAsyncOptions } from './batch-queue-module-options.interface.js'
import type { BatchQueueModuleOptions } from './batch-queue-module-options.interface.js'
import type { BatchQueueOptionsFactory } from './batch-queue-module-options.interface.js'
import type { BatchQueueModuleAsyncOptions } from './batch-queue-module-options.interface.js'
import type { BatchQueueModuleOptions } from './batch-queue-module-options.interface.js'
import type { BatchQueueOptionsFactory } from './batch-queue-module-options.interface.js'

import { Module } from '@nestjs/common'
import { Module } from '@nestjs/common'

import { BATCH_QUEUE_MODULE_OPTIONS } from './constants/index.js'
import { createBatchQueueSyncProvider } from './batch-queue.providers.js'
import { createBatchQueueAsyncProvider } from './batch-queue.providers.js'
import { createMemoryCheckerOptionsSyncProvider } from './batch-queue.providers.js'
import { createMemoryCheckerOptionsAsyncProvider } from './batch-queue.providers.js'
import { createBatchQueueConsumerProvider } from './batch-queue.providers.js'
import { createBatchQueueProducerProvider } from './batch-queue.providers.js'
import { createBatchQueueCheckerProvider } from './batch-queue.providers.js'
import { createBatchQueueStateHandlerProvider } from './batch-queue.providers.js'
import { exportsProviders } from './batch-queue.providers.js'
import { BATCH_QUEUE_MODULE_OPTIONS } from './constants/index.js'
import { createBatchQueueSyncProvider } from './batch-queue.providers.js'
import { createBatchQueueAsyncProvider } from './batch-queue.providers.js'
import { createBatchQueueConsumerProvider } from './batch-queue.providers.js'
import { createBatchQueueProducerProvider } from './batch-queue.providers.js'
import { createBatchQueueCheckerProvider } from './batch-queue.providers.js'
import { createBatchQueueStateHandlerProvider } from './batch-queue.providers.js'
import { exportsProviders } from './batch-queue.providers.js'

@Module({})
export class BatchQueueModule {
static register = (options: BatchQueueModuleOptions): DynamicModule => ({
module: BatchQueueModule,
providers: [
createBatchQueueSyncProvider(options),
createMemoryCheckerOptionsSyncProvider(options),
createBatchQueueConsumerProvider(),
createBatchQueueProducerProvider(),
createBatchQueueCheckerProvider(),
Expand All @@ -46,7 +43,6 @@ export class BatchQueueModule {
const providers: Array<Provider> = [
this.createAsyncOptionsProvider(options),
createBatchQueueAsyncProvider(),
createMemoryCheckerOptionsAsyncProvider(),
createBatchQueueConsumerProvider(),
createBatchQueueProducerProvider(),
createBatchQueueCheckerProvider(),
Expand Down
16 changes: 0 additions & 16 deletions packages/nestjs-batch-queue/src/module/batch-queue.providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { Checker } from '../batch-queue/index.js'
import { StateHandler } from '../batch-queue/index.js'
import { BATCH_QUEUE_MODULE_OPTIONS } from './constants/index.js'
import { BATCH_QUEUE } from './constants/index.js'
import { MEMORY_CHECKER_OPTIONS } from './constants/index.js'
import { BATCH_QUEUE_CONSUMER } from './constants/index.js'
import { BATCH_QUEUE_PRODUCER } from './constants/index.js'
import { BATCH_QUEUE_CHECKER } from './constants/index.js'
Expand All @@ -29,20 +28,6 @@ export const createBatchQueueAsyncProvider = (): Provider => ({
inject: [BATCH_QUEUE_MODULE_OPTIONS],
})

export const createMemoryCheckerOptionsSyncProvider = (
batchQueueModuleOptions: BatchQueueModuleOptions
): Provider => ({
provide: MEMORY_CHECKER_OPTIONS,
useValue: batchQueueModuleOptions.memoryCheckerOptions,
})

export const createMemoryCheckerOptionsAsyncProvider = (): Provider => ({
provide: MEMORY_CHECKER_OPTIONS,
useFactory: (batchQueueModuleOptions: BatchQueueModuleOptions): any =>
batchQueueModuleOptions.memoryCheckerOptions,
inject: [BATCH_QUEUE_MODULE_OPTIONS],
})

export const createBatchQueueConsumerProvider = (): Provider => ({
provide: BATCH_QUEUE_CONSUMER,
useFactory: (batchQueue: BatchQueue<any>): Consumer => new Consumer(batchQueue),
Expand Down Expand Up @@ -72,5 +57,4 @@ export const exportsProviders = [
BATCH_QUEUE_PRODUCER,
BATCH_QUEUE_CHECKER,
BATCH_QUEUE_STATE_HANDLER,
MEMORY_CHECKER_OPTIONS,
]
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ export const BATCH_QUEUE_CONSUMER = Symbol('BATCH_QUEUE_CONSUMER')
export const BATCH_QUEUE_PRODUCER = Symbol('BATCH_QUEUE_PRODUCER')
export const BATCH_QUEUE_CHECKER = Symbol('BATCH_QUEUE_CHECKER')
export const BATCH_QUEUE_STATE_HANDLER = Symbol('BATCH_QUEUE_STATE_HANDLER')
export const MEMORY_CHECKER_OPTIONS = Symbol('MEMORY_CHECKER_OPTIONS')

0 comments on commit 236c771

Please sign in to comment.