Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
mrinc committed Sep 16, 2022
2 parents 8c7a7e6 + 621ac80 commit ba9230a
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 10 deletions.
9 changes: 4 additions & 5 deletions src/plugins/service-default1/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class Service
this.emitEvent("onEmittable", a, b);
return a * b;
}
async init() {
public override async init() {
const self = this;
this.onEvent("onReceivable", async (a: number, b: number) => {
self.log.warn("received onReceivable ({a},{b}", { a, b });
Expand Down Expand Up @@ -64,8 +64,7 @@ export class testClient extends ServicesClient<
) {
super(self);
}
public async register(): Promise<void> {
await this._register();
public async init(): Promise<void> {
const self = this;
this._plugin.onEvent("onEmittable", async (a: number, b: number) => {
self._plugin.log.warn("onEmittable ({a},{b})", { a, b });
Expand All @@ -80,10 +79,10 @@ export class testClient extends ServicesClient<
this._plugin.emitEvent("onReceivable", 56, 7);
}
async abc(): Promise<void> {
this._plugin.log.warn("TESTING ABC CALL ({result})", {
await this._plugin.log.warn("TESTING ABC CALL ({result})", {
result: await this._plugin.callPluginMethod("callableMethod", 5, 8),
});
this._plugin.log.warn("TESTING onReturnable ({result})", {
await this._plugin.log.warn("TESTING onReturnable ({result})", {
result: await this._plugin.emitEventAndReturn("onReturnable", 12, 8),
});
}
Expand Down
15 changes: 11 additions & 4 deletions src/plugins/service-default2/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import { IPluginLogger } from '../../interfaces/logger';
import { ServicesBase } from "../../service/service";
import { testClient } from "../service-default1/plugin";

export class Service extends ServicesBase {
public override initAfterPlugins: string[] = ["service-default1"];
async run() {
let ppp = new testClient(this);
await ppp.register();
ppp.abc();
private testClient: testClient;
constructor(pluginName: string, cwd: string, log: IPluginLogger) {
super(pluginName, cwd, log);
this.testClient = new testClient(this);
}
public override async init() {
await this.testClient.init();
}
public override async run() {
await this.testClient.abc();
}
}
3 changes: 2 additions & 1 deletion src/service/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { IPluginLogger } from "../interfaces/logger";
import { IService } from "../interfaces/service";
import { Readable } from "stream";
import { DefaultBase } from "../interfaces/base";
import { RegisteredPlugin } from "./serviceClient";
import { RegisteredPlugin, ServicesClient } from "./serviceClient";
import { ErrorMessages } from "../interfaces/static";
import {
DynamicallyReferencedMethodType,
Expand Down Expand Up @@ -57,6 +57,7 @@ export class ServicesBase<
throw ErrorMessages.BSBNotInit;
}

protected _clients: Array<ServicesClient> = [];
constructor(pluginName: string, cwd: string, log: IPluginLogger) {
super(pluginName, cwd, log);
if (Tools.isNullOrUndefined(this.initBeforePlugins)) this.initBeforePlugins = [];
Expand Down
1 change: 1 addition & 0 deletions src/service/serviceClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,5 +155,6 @@ export class ServicesClient<
(self as any).initAfterPlugins = self.initAfterPlugins!.concat(this.initAfterPlugins!);
(self as any).runBeforePlugins = self.runBeforePlugins!.concat(this.runBeforePlugins!);
(self as any).runAfterPlugins = self.runAfterPlugins!.concat(this.runAfterPlugins!);
(self as any)._clients.push(this);
}
}
3 changes: 3 additions & 0 deletions src/serviceBase/serviceBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,9 @@ export class ServiceBase {
this._startKeep(BOOT_STAT_KEYS.SERVICES);
const self = this;
await this._services.setupServicePlugins(
this._appId,
this._runningDebug,
this._runningLive,
this.cwd,
this.plugins,
this._config.appConfig,
Expand Down
24 changes: 24 additions & 0 deletions src/serviceBase/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ export class SBServices {
}

async setupServicePlugins(
appId: string,
runningDebug: boolean,
runningLive: boolean,
cwd: string,
plugins: Array<IReadyPlugin>,
appConfig: ConfigBase,
Expand Down Expand Up @@ -68,6 +71,7 @@ export class SBServices {
pluginName: plugin.name,
});
const self = this;
SBBase.setupPlugin(appId, runningDebug, runningLive, servicePlugin, appConfig);
await SBBase.setupServicePlugin(
servicePlugin,
await generateEventsForService(plugin.name, plugin.mappedName),
Expand All @@ -90,6 +94,26 @@ export class SBServices {
}
);

await this.log.info(
"Setup {pluginName} ({mappedName}) referenced clients",
{
pluginName: plugin.name,
mappedName: plugin.mappedName,
}
);

for (let client of ((servicePlugin as any)._clients)) {
await this.log.info(
"Setup {pluginName} ({mappedName}) references {clientPlugin}",
{
pluginName: plugin.name,
mappedName: plugin.mappedName,
clientPlugin: client._pluginName
}
);
await client._register();
}

await this.log.info(
"Ready {pluginName} ({mappedName}) as new base service platform",
{
Expand Down

0 comments on commit ba9230a

Please sign in to comment.