Skip to content

Commit

Permalink
Merge pull request #80 from ainize-team/fix/yoojin/is_running
Browse files Browse the repository at this point in the history
Fix isRunning function returns boolean
  • Loading branch information
yoojinko authored Dec 11, 2023
2 parents d4d3076 + dabebdf commit 14e1133
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
17 changes: 11 additions & 6 deletions src/controllers/serviceController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,18 @@ export default class ServiceController {
return ServiceController.instance;
}

async isRunning(serviceName: string): Promise<void> {
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<void> {
const isRunning = await this.isRunning(serviceName);
if (!isRunning) {
throw new Error('Service is not running.');
}
}

async isRunning(serviceName: string): Promise<boolean> {
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<any> {
return await 'information of service';
Expand All @@ -42,7 +47,7 @@ export default class ServiceController {
}

async chargeCredit(serviceName: string, amount: number): Promise<string> {
this.isRunning(serviceName);
this.checkRunning(serviceName);
const transferKey = Date.now();
const userAddress = this.ain.getAddress();
const depositAddress = await this.getDepositAddress(serviceName);
Expand Down Expand Up @@ -72,7 +77,7 @@ export default class ServiceController {
}

async request(serviceName: string, requestData: string) : Promise<string> {
this.isRunning(serviceName);
this.checkRunning(serviceName);
const result = await new Promise(async (resolve, reject) => {
const requestKey = Date.now();
const requesterAddress = this.ain.getAddress();
Expand Down
5 changes: 3 additions & 2 deletions src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean>}
*/
async isRunning() {
return await this.serviceController.isRunning(this.serviceName);
}

/**
* Get service information. not implemented yet.
* @returns {string} Service information.
Expand Down

0 comments on commit 14e1133

Please sign in to comment.