From 3262d40ca5066b7f289881c90daa2bc7d88f5505 Mon Sep 17 00:00:00 2001 From: akaster99 Date: Wed, 20 Sep 2023 14:02:45 +0900 Subject: [PATCH 1/2] feat: connect --- src/ainize.ts | 2 ++ src/controllers/modelController.ts | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/ainize.ts b/src/ainize.ts index 8ed15fe..ae8550f 100644 --- a/src/ainize.ts +++ b/src/ainize.ts @@ -9,11 +9,13 @@ import AinModule from "./ain"; export default class Ainize { private cache: NodeCache; ain: AinModule = AinModule.getInstance(); + private handler: Handler = Handler.getInstance(); middleware: Middleware; appController: AppController = AppController.getInstance(); constructor(chainId: 1 | 0) { this.ain.initAin(chainId); + this.handler.connect(); this.cache = new NodeCache(); this.middleware = new Middleware(this.cache); } diff --git a/src/controllers/modelController.ts b/src/controllers/modelController.ts index 6c5bb3f..dd90643 100644 --- a/src/controllers/modelController.ts +++ b/src/controllers/modelController.ts @@ -4,6 +4,7 @@ import { Path } from "../constants"; import { getRequestDepositOp, getTransferOp } from "../utils/operator"; import { buildSetOperation, buildTxBody } from "../utils/builder"; import Handler from "../handlers/handler"; +import { ContainerStatus } from "../types/type"; export default class ModelController { private static instance: ModelController | undefined; @@ -16,9 +17,9 @@ export default class ModelController { return ModelController.instance; } - //TODO(woojae): implement this async isRunning(modelName: string) { - return await true; + const isRunning = await this.ain.getValue(Path.app(modelName).status()); + return isRunning === ContainerStatus.RUNNING; } //TODO(woojae): implement this @@ -40,6 +41,7 @@ export default class ModelController { async chargeCredit(modelName: string, amount: number) { this.isLoggedIn(); + this.isRunning(modelName); const transferKey = Date.now(); const userAddress = this.ain.getAddress(); const depositAddress = await this.getDepositAddress(modelName); @@ -74,6 +76,7 @@ export default class ModelController { //TODO(woojae): connect with handler async use(modelName: string, requestData: string) { this.isLoggedIn(); + this.isRunning(modelName); const result = await new Promise(async (resolve, reject) => { const requestKey = Date.now(); const requesterAddress = this.ain.getAddress(); From fbf5971f880d617bbab2f1402ca0b4c0b0042bcf Mon Sep 17 00:00:00 2001 From: akaster99 Date: Wed, 20 Sep 2023 14:06:41 +0900 Subject: [PATCH 2/2] feat: isRunning --- src/controllers/modelController.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/controllers/modelController.ts b/src/controllers/modelController.ts index dd90643..91c5f7b 100644 --- a/src/controllers/modelController.ts +++ b/src/controllers/modelController.ts @@ -19,7 +19,9 @@ export default class ModelController { async isRunning(modelName: string) { const isRunning = await this.ain.getValue(Path.app(modelName).status()); - return isRunning === ContainerStatus.RUNNING; + if(isRunning !== ContainerStatus.RUNNING) { + throw new Error('Model is not running'); + } } //TODO(woojae): implement this