Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Test, TestingModule } from '@nestjs/testing';
import { v4 as uuidv4 } from 'uuid';
import { when } from 'jest-when';
import { mockDatabase, mockWorkbenchAnalyticsService } from 'src/__mocks__';
import { mockDatabase, mockDatabaseConnectionService, mockWorkbenchAnalyticsService } from 'src/__mocks__';
import { IFindRedisClientInstanceByOptions } from 'src/modules/redis/redis.service';
import { WorkbenchService } from 'src/modules/workbench/workbench.service';
import { WorkbenchCommandsExecutor } from 'src/modules/workbench/providers/workbench-commands.executor';
Expand All @@ -17,6 +17,7 @@ import { CommandExecutionResult } from 'src/modules/workbench/models/command-exe
import { CommandExecutionStatus } from 'src/modules/cli/dto/cli.dto';
import { BadRequestException, InternalServerErrorException } from '@nestjs/common';
import ERROR_MESSAGES from 'src/constants/error-messages';
import { DatabaseConnectionService } from 'src/modules/database/database-connection.service';
import { CreateCommandExecutionsDto } from 'src/modules/workbench/dto/create-command-executions.dto';
import { WorkbenchAnalyticsService } from './services/workbench-analytics/workbench-analytics.service';

Expand Down Expand Up @@ -126,6 +127,10 @@ describe('WorkbenchService', () => {
provide: CommandExecutionProvider,
useFactory: mockCommandExecutionProvider,
},
{
provide: DatabaseConnectionService,
useFactory: mockDatabaseConnectionService,
},
],
}).compile();

Expand Down
10 changes: 10 additions & 0 deletions redisinsight/api/src/modules/workbench/workbench.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ import { getBlockingCommands, multilineCommandToOneLine } from 'src/utils/cli-he
import ERROR_MESSAGES from 'src/constants/error-messages';
import { ShortCommandExecution } from 'src/modules/workbench/models/short-command-execution';
import { CommandExecutionStatus } from 'src/modules/cli/dto/cli.dto';
import { DatabaseConnectionService } from 'src/modules/database/database-connection.service';
import { AppTool } from 'src/models';
import { getUnsupportedCommands } from './utils/getUnsupportedCommands';
import { WorkbenchAnalyticsService } from './services/workbench-analytics/workbench-analytics.service';

@Injectable()
export class WorkbenchService {
constructor(
private readonly databaseConnectionService: DatabaseConnectionService,
private commandsExecutor: WorkbenchCommandsExecutor,
private commandExecutionProvider: CommandExecutionProvider,
private analyticsService: WorkbenchAnalyticsService,
Expand Down Expand Up @@ -127,6 +130,13 @@ export class WorkbenchService {
clientOptions: IFindRedisClientInstanceByOptions,
dto: CreateCommandExecutionsDto,
): Promise<CommandExecution[]> {
// todo: handle concurrent client creation on RedisModule side
// temporary workaround. Just create client before any command execution precess
await this.databaseConnectionService.getOrCreateClient({
databaseId: clientOptions.instanceId,
namespace: AppTool.Workbench,
});

if (dto.resultsMode === ResultsMode.GroupMode) {
return this.commandExecutionProvider.createMany(
[await this.createCommandsExecution(clientOptions, dto, dto.commands)],
Expand Down