diff --git a/package.json b/package.json index 5c95387..bb1727b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ainize-team/ainize-js", - "version": "1.0.3", + "version": "1.0.4", "main": "dist/ainize.js", "types": "dist/ainize.d.ts", "scripts": { diff --git a/src/controllers/serviceController.ts b/src/controllers/serviceController.ts index 1c97646..f5bbfbe 100644 --- a/src/controllers/serviceController.ts +++ b/src/controllers/serviceController.ts @@ -17,13 +17,18 @@ export default class ServiceController { return ServiceController.instance; } - async isRunning(serviceName: string): Promise { - const isRunning = await this.ain.getValue(Path.app(serviceName).status()); - if(isRunning !== ContainerStatus.RUNNING) { - throw new Error('Service is not running'); + async checkRunning(serviceName: string): Promise { + const isRunning = await this.isRunning(serviceName); + if (!isRunning) { + throw new Error('Service is not running.'); } } + async isRunning(serviceName: string): Promise { + const runningStatus = await this.ain.getValue(Path.app(serviceName).status()); + return runningStatus === ContainerStatus.RUNNING ? true : false; + } + // TODO(woojae): implement this async getInformation(serviceName: string): Promise { return await 'information of service'; @@ -43,7 +48,7 @@ export default class ServiceController { } async chargeCredit(serviceName: string, amount: number): Promise { - this.isRunning(serviceName); + this.checkRunning(serviceName); const transferKey = Date.now(); const userAddress = this.ain.getAddress(); const depositAddress = await this.getDepositAddress(serviceName); @@ -73,7 +78,7 @@ export default class ServiceController { } async request(serviceName: string, requestData: any) : Promise { - this.isRunning(serviceName); + this.checkRunning(serviceName); const result = await new Promise(async (resolve, reject) => { const requestKey = Date.now(); const requesterAddress = this.ain.getAddress(); diff --git a/src/service.ts b/src/service.ts index 1c86ecf..24239da 100644 --- a/src/service.ts +++ b/src/service.ts @@ -10,12 +10,13 @@ export default class Service { } /** - * Check if service is running. It throws error when service is not running. + * Gets whether the service is running or not. + * @returns {Promise} */ async isRunning() { return await this.serviceController.isRunning(this.serviceName); } - + /** * Get service information. not implemented yet. * @returns {string} Service information.