Skip to content

Commit

Permalink
feat(deployment): implement concurrency option for stale deployments …
Browse files Browse the repository at this point in the history
…cleaner
  • Loading branch information
ygrishajev committed Nov 18, 2024
1 parent 26b25a8 commit 54cae5d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
4 changes: 3 additions & 1 deletion apps/api/src/console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { LoggerService } from "@akashnetwork/logging";
import { context, trace } from "@opentelemetry/api";
import { Command } from "commander";
import { container } from "tsyringe";
import { z } from "zod";

import { WalletController } from "@src/billing/controllers/wallet/wallet.controller";
import { chainDb } from "@src/db/dbConnection";
Expand Down Expand Up @@ -41,9 +42,10 @@ program
program
.command("cleanup-stale-deployments")
.description("Close deployments without leases created at least 10min ago")
.option("-c, --concurrency <number>", "How much wallets is processed concurrently", value => z.number({ coerce: true }).optional().default(10).parse(value))
.action(async (options, command) => {
await executeCliHandler(command.name(), async () => {
await container.resolve(TopUpDeploymentsController).cleanUpStaleDeployment();
await container.resolve(TopUpDeploymentsController).cleanUpStaleDeployment(options);
});
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { singleton } from "tsyringe";

import { StaleManagedDeploymentsCleanerService } from "@src/deployment/services/stale-managed-deployments-cleaner/stale-managed-deployments-cleaner.service";
import {
CleanUpStaleDeploymentsParams,
StaleManagedDeploymentsCleanerService
} from "@src/deployment/services/stale-managed-deployments-cleaner/stale-managed-deployments-cleaner.service";
import { TopUpCustodialDeploymentsService } from "@src/deployment/services/top-up-custodial-deployments/top-up-custodial-deployments.service";
import { TopUpManagedDeploymentsService } from "@src/deployment/services/top-up-managed-deployments/top-up-managed-deployments.service";
import { TopUpDeploymentsOptions } from "@src/deployment/types/deployments-refiller";
Expand All @@ -18,7 +21,7 @@ export class TopUpDeploymentsController {
await this.topUpManagedDeploymentsService.topUpDeployments(options);
}

async cleanUpStaleDeployment() {
await this.staleDeploymentsCleanerService.cleanup();
async cleanUpStaleDeployment(options: CleanUpStaleDeploymentsParams) {
await this.staleDeploymentsCleanerService.cleanup(options);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import { ErrorService } from "@src/core/services/error/error.service";
import { DeploymentRepository } from "@src/deployment/repositories/deployment/deployment.repository";
import { averageBlockTime } from "@src/utils/constants";

export interface CleanUpStaleDeploymentsParams {
concurrency: number;
}

@singleton()
export class StaleManagedDeploymentsCleanerService {
private readonly logger = LoggerService.forContext(StaleManagedDeploymentsCleanerService.name);
Expand All @@ -28,8 +32,8 @@ export class StaleManagedDeploymentsCleanerService {
private readonly errorService: ErrorService
) {}

async cleanup() {
await this.userWalletRepository.paginate({ limit: 10 }, async wallets => {
async cleanup(options: CleanUpStaleDeploymentsParams) {
await this.userWalletRepository.paginate({ limit: options.concurrency || 10 }, async wallets => {
const cleanUpAllWallets = wallets.map(async wallet => {
await this.errorService.execWithErrorHandler(
{
Expand Down
2 changes: 1 addition & 1 deletion apps/deploy-web/next-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/// <reference types="next/image-types/global" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/basic-features/typescript for more information.
// see https://nextjs.org/docs/pages/building-your-application/configuring/typescript for more information.

0 comments on commit 54cae5d

Please sign in to comment.