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..91c5f7b 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,11 @@ 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()); + if(isRunning !== ContainerStatus.RUNNING) { + throw new Error('Model is not running'); + } } //TODO(woojae): implement this @@ -40,6 +43,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 +78,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();