From c6bc5fe9c0fcbbd7f07d0a50a02031b58343f791 Mon Sep 17 00:00:00 2001 From: Yaroslav Grishajev Date: Mon, 28 Oct 2024 10:36:32 +0100 Subject: [PATCH] feat(deployment): implements basic top up handler w/o implementation Also extracts common CLI command preps and tear downs to a function refs #395 --- apps/api/src/console.ts | 36 +++++++++++++------ .../deployment/deployment.controller.ts | 12 +++++++ .../top-up-deployments.service.ts | 12 +++++++ package-lock.json | 4 +-- 4 files changed, 52 insertions(+), 12 deletions(-) create mode 100644 apps/api/src/deployment/controllers/deployment/deployment.controller.ts create mode 100644 apps/api/src/deployment/services/top-up-deployments/top-up-deployments.service.ts diff --git a/apps/api/src/console.ts b/apps/api/src/console.ts index a4b7e5873..09cd53484 100644 --- a/apps/api/src/console.ts +++ b/apps/api/src/console.ts @@ -8,6 +8,7 @@ import { container } from "tsyringe"; import { WalletController } from "@src/billing/controllers/wallet/wallet.controller"; import { LoggerService } from "@src/core"; +import { TopUpDeploymentsController } from "@src/deployment/controllers/deployment/deployment.controller"; const program = new Command(); @@ -17,19 +18,34 @@ const tracer = trace.getTracer("API Console"); program .command("refill-wallets") .description("Refill draining wallets") - .action(async () => { - await context.with(trace.setSpan(context.active(), tracer.startSpan("refill-wallets")), async () => { - const logger = new LoggerService({ context: "CLI" }); - logger.info("Refilling wallets"); - // eslint-disable-next-line @typescript-eslint/no-var-requires - const { migratePG, closeConnections } = await require("./core/providers/postgres.provider"); - await migratePG(); - + .action(async (options, command) => { + await executeCliHandler(command.name(), async () => { await container.resolve(WalletController).refillWallets(); + }); + }); - await closeConnections(); - logger.info("Finished refilling wallets"); +program + .command("top-up-deployments") + .description("Refill deployments with auto top up enabled") + .action(async (options, command) => { + await executeCliHandler(command.name(), async () => { + await container.resolve(TopUpDeploymentsController).topUpDeployments(); }); }); +async function executeCliHandler(name: string, handler: () => Promise) { + await context.with(trace.setSpan(context.active(), tracer.startSpan(name)), async () => { + const logger = new LoggerService({ context: "CLI" }); + logger.info({ event: "COMMAND_START", name }); + // eslint-disable-next-line @typescript-eslint/no-var-requires + const { migratePG, closeConnections } = await require("./core/providers/postgres.provider"); + await migratePG(); + + await handler(); + + await closeConnections(); + logger.info({ event: "COMMAND_END", name }); + }); +} + program.parse(); diff --git a/apps/api/src/deployment/controllers/deployment/deployment.controller.ts b/apps/api/src/deployment/controllers/deployment/deployment.controller.ts new file mode 100644 index 000000000..73ec8b161 --- /dev/null +++ b/apps/api/src/deployment/controllers/deployment/deployment.controller.ts @@ -0,0 +1,12 @@ +import { singleton } from "tsyringe"; + +import { TopUpDeploymentsService } from "@src/deployment/services/top-up-deployments/top-up-deployments.service"; + +@singleton() +export class TopUpDeploymentsController { + constructor(private readonly topUpDeploymentsService: TopUpDeploymentsService) {} + + async topUpDeployments() { + await this.topUpDeploymentsService.topUpDeployments(); + } +} diff --git a/apps/api/src/deployment/services/top-up-deployments/top-up-deployments.service.ts b/apps/api/src/deployment/services/top-up-deployments/top-up-deployments.service.ts new file mode 100644 index 000000000..a9127e00c --- /dev/null +++ b/apps/api/src/deployment/services/top-up-deployments/top-up-deployments.service.ts @@ -0,0 +1,12 @@ +import { singleton } from "tsyringe"; + +import { LoggerService } from "@src/core"; + +@singleton() +export class TopUpDeploymentsService { + private readonly logger = new LoggerService({ context: TopUpDeploymentsService.name }); + + async topUpDeployments() { + this.logger.warn("Top up deployments not implemented"); + } +} diff --git a/package-lock.json b/package-lock.json index 453bf5ab9..0c18ca3d6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -31,7 +31,7 @@ }, "apps/api": { "name": "@akashnetwork/console-api", - "version": "2.25.0", + "version": "2.26.0", "license": "Apache-2.0", "dependencies": { "@akashnetwork/akash-api": "^1.3.0", @@ -270,7 +270,7 @@ }, "apps/deploy-web": { "name": "@akashnetwork/console-web", - "version": "2.19.1-beta.0", + "version": "2.20.1", "license": "Apache-2.0", "dependencies": { "@akashnetwork/akash-api": "^1.3.0",