Skip to content

Commit

Permalink
feat(deployment): implements basic top up handler w/o implementation
Browse files Browse the repository at this point in the history
Also extracts common CLI command preps and tear downs to a function

refs #395
  • Loading branch information
ygrishajev committed Oct 29, 2024
1 parent 7b33801 commit a4cd312
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 12 deletions.
36 changes: 26 additions & 10 deletions apps/api/src/console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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<void>) {
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();
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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");
}
}
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a4cd312

Please sign in to comment.