|
1 | 1 | import { DynamicModule, Module, Provider } from '@nestjs/common';
|
2 | 2 | import { DiscoveryModule } from '@nestjs/core';
|
| 3 | +import { EventEmitter } from 'events'; |
| 4 | +import { RunnerOptions } from 'graphile-worker'; |
3 | 5 | import {
|
4 | 6 | GraphileWorkerAsyncConfiguration,
|
| 7 | + GraphileWorkerConfiguration, |
5 | 8 | GraphileWorkerConfigurationFactory,
|
6 |
| - RunnerOptionWithoutEvents, |
| 9 | + RUNNER_OPTIONS_KEY, |
7 | 10 | } from './interfaces/module-config.interfaces';
|
8 |
| -import { |
9 |
| - ConfigurationService, |
10 |
| - CONFIGURATION_SERVICE_KEY, |
11 |
| -} from './services/configuration.service'; |
12 | 11 | import { ListenerExplorerService } from './services/listener-explorer.service';
|
13 | 12 | import { MetadataAccessorService } from './services/metadata-accessor.service';
|
14 | 13 | import { WorkerService } from './services/worker.service';
|
@@ -42,12 +41,10 @@ export class GraphileWorkerModule {
|
42 | 41 | * }),
|
43 | 42 | * ```
|
44 | 43 | */
|
45 |
| - static forRoot(config: RunnerOptionWithoutEvents): DynamicModule { |
46 |
| - const configurationService = new ConfigurationService(config); |
47 |
| - |
| 44 | + static forRoot(config: GraphileWorkerConfiguration): DynamicModule { |
48 | 45 | const graphileConfigurationServiceProvider: Provider = {
|
49 |
| - provide: CONFIGURATION_SERVICE_KEY, |
50 |
| - useValue: configurationService, |
| 46 | + provide: RUNNER_OPTIONS_KEY, |
| 47 | + useValue: config, |
51 | 48 | };
|
52 | 49 |
|
53 | 50 | return {
|
@@ -102,24 +99,35 @@ export class GraphileWorkerModule {
|
102 | 99 | ): Provider {
|
103 | 100 | if (options.useFactory) {
|
104 | 101 | return {
|
105 |
| - provide: CONFIGURATION_SERVICE_KEY, |
| 102 | + provide: RUNNER_OPTIONS_KEY, |
| 103 | + inject: options.inject || [], |
106 | 104 | useFactory: async (...args: any[]) => {
|
107 | 105 | const config = await options.useFactory(...args);
|
108 |
| - return new ConfigurationService(config); |
| 106 | + return buildRunnerOptions(config); |
109 | 107 | },
|
110 |
| - inject: options.inject || [], |
111 | 108 | };
|
112 | 109 | }
|
113 | 110 |
|
114 | 111 | return {
|
115 |
| - provide: CONFIGURATION_SERVICE_KEY, |
| 112 | + provide: RUNNER_OPTIONS_KEY, |
| 113 | + inject: options.inject, |
116 | 114 | useFactory: async (
|
117 | 115 | optionsFactory: GraphileWorkerConfigurationFactory,
|
118 | 116 | ) => {
|
119 | 117 | const config = await optionsFactory.createSharedConfiguration();
|
120 |
| - return new ConfigurationService(config); |
| 118 | + return buildRunnerOptions(config); |
121 | 119 | },
|
122 |
| - inject: options.inject, |
123 | 120 | };
|
124 | 121 | }
|
125 | 122 | }
|
| 123 | + |
| 124 | +function buildRunnerOptions( |
| 125 | + configuration: GraphileWorkerConfiguration, |
| 126 | +): RunnerOptions { |
| 127 | + const events = new EventEmitter(); |
| 128 | + |
| 129 | + return { |
| 130 | + ...configuration, |
| 131 | + events, |
| 132 | + }; |
| 133 | +} |
0 commit comments