Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix isRunning function returns boolean #80

Merged
merged 5 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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