Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async configuration does not allow an array of BullModuleOptions[] #13

Closed
CodebyOmar opened this issue Mar 20, 2019 · 5 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@CodebyOmar
Copy link

BullModule.forRootAsync({
  import: [PayModule],
  inject: [PayService],
  useFactory: async (payService: PayService) => {
    return [
      {
        name: 'settlement',
        options: {
          redis: {
            port: 6379
          }
       },
       {
        name: 'collation',
        options: {
          redis: {
            port: 6379
          }
        }
      }
    ]  
  }
})
@fwoelffel
Copy link
Contributor

Might be related to #12

@fwoelffel fwoelffel added the bug Something isn't working label Mar 20, 2019
@fwoelffel
Copy link
Contributor

Hi @CodebyOmar could you provide some information on the observed behavior?

@fwoelffel fwoelffel self-assigned this Mar 20, 2019
@CodebyOmar
Copy link
Author

CodebyOmar commented Mar 20, 2019

I went through the code;

export interface BullModuleOptions {
  name?: string;
  options?: Bull.QueueOptions;
  processors?: BullQueueProcessor[];
}

export interface BullOptionsFactory {
  createBullOptions(): Promise<BullModuleOptions> | BullModuleOptions;
}

export interface BullModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
  name?: string;
  useExisting?: Type<BullOptionsFactory>;
  useClass?: Type<BullOptionsFactory>;
  useFactory?: (...args: any[]) => Promise<BullModuleOptions> | BullModuleOptions;
  inject?: any[];
}

Notice: The function createBullOptions in the interface BullOptionsFactory returns a promise of BullModuleOptions or BullModuleOptions but an array of BullModuleOptions is not specified.

@CodebyOmar
Copy link
Author

Has anyone found a solution to this? Its critical to our project right now please.

fwoelffel added a commit that referenced this issue Apr 4, 2019
@fwoelffel
Copy link
Contributor

Hi @CodebyOmar
I've worked on this today and came up with a working implementation of the requested feature. You're right, this should've been done from the beginning.

However, things do not work exactly as suggested by you code sample but rather like this:

BullModule.forRootAsync([
  {
    name: 'settlement',
    imports: [PayModule],
    inject: [PayService],
    useFactory: (payService: PayService) => ({
      options: {
        redis: {
          port: 6379
        }
      }
    })
  },
  {
    name: 'collation',
    imports: [PayModule],
    inject: [PayService],
    useFactory: (payService: PayService) => ({
      options: {
        redis: {
          port: 6379
        }
      }
    })
  },
])

I'll most probably release this tomorrow. I'd like to add some more tests before. Feel free to share your feedback about this implementation since it does not exactly match your expectations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants