Skip to content

Commit

Permalink
Merge pull request #47 from ainize-team/feat/woojae/status
Browse files Browse the repository at this point in the history
feat: connect
  • Loading branch information
akastercomcom authored Sep 20, 2023
2 parents cc06695 + fbf5971 commit 2d27a44
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/ainize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
9 changes: 7 additions & 2 deletions src/controllers/modelController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 2d27a44

Please sign in to comment.