Skip to content

Commit

Permalink
fix: config handler workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
ChoGathK committed Oct 16, 2022
1 parent aef06f4 commit 225dd7c
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 19 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"dependencies": {
"@nestjs/common": "^8.4.7",
"@vodyani/class-decorator": "^8.2.3",
"@vodyani/core": "^8.9.7",
"@vodyani/core": "^8.9.8",
"@vodyani/utils": "^8.7.1",
"js-yaml": "^4.1.0",
"lodash": "4.17.21"
Expand Down
20 changes: 10 additions & 10 deletions src/provider/ark-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { FactoryProvider } from '@nestjs/common';
import { This } from '@vodyani/class-decorator';
import { AsyncInjectable, AsyncProviderFactory } from '@vodyani/core';

import { ConfigHandlerOptions } from '../common';
import { ConfigHandlerOptions, IConfigHandler } from '../common';
import { ConfigClientSubscriber } from '../struct';
import { ConfigArgumentHandler, ConfigClientHandler, DynamicDataSourceConfigObserverHandler } from '../struct/config-handler';

Expand Down Expand Up @@ -36,27 +36,27 @@ export class ArkManager extends AsyncProviderFactory {
config: ConfigProvider,
observer?: DynamicDataSourceConfigObserver,
) {
const handlers = [];
const handler = new ConfigArgumentHandler(config);
const flow: IConfigHandler[] = [];
const concreteHandler = new ConfigArgumentHandler(config);

flow.push(concreteHandler);

if (this.options.clients) {
const handler = flow.pop();
const subscriber = new ConfigClientSubscriber(config);
const clientHandler = new ConfigClientHandler(config, subscriber);

handlers.push(clientHandler);
flow.push(handler.setNext(clientHandler));
}

if (this.options.enableDynamicDataSource) {
const handler = flow.pop();
const observerHandler = new DynamicDataSourceConfigObserverHandler(observer);

handlers.push(observerHandler);
}

while (handlers.length > 0) {
handler.setNext(handlers.shift());
flow.push(handler.setNext(observerHandler));
}

await handler.execute(this.options);
await concreteHandler.execute(this.options);

return config;
}
Expand Down
8 changes: 8 additions & 0 deletions src/struct/config-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,12 @@ export class LocalConfigClient implements IConfigClient {
public unSubscribe() {
this.subscriber = null;
}

public polling() {
// do something ...
}

public unPolling() {
// do something ...
}
}
1 change: 0 additions & 1 deletion src/struct/config-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ abstract class AbstractConfigHandler<T = any> implements IConfigHandler<T> {

public setNext(handler: IConfigHandler) {
this.next = handler;

return handler;
}

Expand Down
2 changes: 2 additions & 0 deletions test/struct/config-client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ describe('LocalConfigClient', () => {

public polling(): void {
this.contrast({ poller: 'DemoConfigClient' });
super.polling();
super.unPolling();
}

public contrast(value: any) {
Expand Down
2 changes: 2 additions & 0 deletions test/struct/config-handler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class DemoConfigClient extends LocalConfigClient {

public polling(): void {
this.contrast({ poller: 'DemoConfigClient' });
super.polling();
super.unPolling();
}

public contrast(value: any) {
Expand Down

0 comments on commit 225dd7c

Please sign in to comment.