Skip to content

Commit 07e56dc

Browse files
Merge pull request #3555 from RedisInsight/bugfix/rdi_jobs
mark jobs as optional
2 parents 5fa26f4 + a2dc5b1 commit 07e56dc

File tree

17 files changed

+67
-51
lines changed

17 files changed

+67
-51
lines changed

redisinsight/api/src/constants/error-messages.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,5 @@ export default {
111111
RDI_DEPLOY_PIPELINE_FAILURE: 'Failed to deploy pipeline',
112112
RDI_TIMEOUT_ERROR: 'Encountered a timeout error while attempting to retrieve data',
113113
RDI_VALIDATION_ERROR: 'Validation error',
114+
INVALID_RDI_INSTANCE_ID: 'Invalid rdi instance id.',
114115
};

redisinsight/api/src/modules/rdi/client/api.rdi.client.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import { RdiClient } from 'src/modules/rdi/client/rdi.client';
66
import {
77
RdiUrl,
88
RDI_TIMEOUT,
9-
TOKEN_TRESHOLD,
9+
TOKEN_THRESHOLD,
1010
POLLING_INTERVAL,
1111
MAX_POLLING_TIME,
12+
WAIT_BEFORE_POLLING,
1213
} from 'src/modules/rdi/constants';
1314
import {
1415
RdiDryRunJobDto,
@@ -17,6 +18,7 @@ import {
1718
RdiTestConnectionsResponseDto,
1819
} from 'src/modules/rdi/dto';
1920
import {
21+
RdiPipelineDeployFailedException,
2022
RdiPipelineInternalServerErrorException,
2123
wrapRdiPipelineError,
2224
} from 'src/modules/rdi/exceptions';
@@ -96,7 +98,7 @@ export class ApiRdiClient extends RdiClient {
9698
const response = await this.client.post(RdiUrl.Deploy, { ...pipeline });
9799
const actionId = response.data.action_id;
98100

99-
return this.pollActionStatus(actionId);
101+
return await this.pollActionStatus(actionId);
100102
} catch (error) {
101103
throw wrapRdiPipelineError(error, error.response.data.message);
102104
}
@@ -174,16 +176,19 @@ export class ApiRdiClient extends RdiClient {
174176
async ensureAuth(): Promise<void> {
175177
const expiresIn = this.auth.exp * 1_000 - Date.now();
176178

177-
if (expiresIn < TOKEN_TRESHOLD) {
179+
if (expiresIn < TOKEN_THRESHOLD) {
178180
await this.connect();
179181
}
180182
}
181183

182184
private async pollActionStatus(actionId: string, abortSignal?: AbortSignal): Promise<any> {
185+
await new Promise((resolve) => setTimeout(resolve, WAIT_BEFORE_POLLING));
186+
183187
const startTime = Date.now();
188+
184189
while (true) {
185190
if (abortSignal?.aborted) {
186-
throw new RdiPipelineInternalServerErrorException();
191+
throw new RdiPipelineInternalServerErrorException('Operation is aborted');
187192
}
188193
if (Date.now() - startTime > MAX_POLLING_TIME) {
189194
throw new RdiPipelineTimeoutException();
@@ -197,7 +202,7 @@ export class ApiRdiClient extends RdiClient {
197202
const { status, data, error } = response.data;
198203

199204
if (status === 'failed') {
200-
throw new RdiPipelineInternalServerErrorException(error?.message);
205+
throw new RdiPipelineDeployFailedException(error?.message);
201206
}
202207

203208
if (status === 'completed') {

redisinsight/api/src/modules/rdi/client/rdi.client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
import {
66
RdiDryRunJobDto, RdiDryRunJobResponseDto, RdiTemplateResponseDto, RdiTestConnectionsResponseDto,
77
} from 'src/modules/rdi/dto';
8-
import { IDLE_TRESHOLD } from 'src/modules/rdi/constants';
8+
import { IDLE_THRESHOLD } from 'src/modules/rdi/constants';
99

1010
export abstract class RdiClient {
1111
public readonly id: string;
@@ -20,7 +20,7 @@ export abstract class RdiClient {
2020
}
2121

2222
public isIdle(): boolean {
23-
return Date.now() - this.lastUsed > IDLE_TRESHOLD;
23+
return Date.now() - this.lastUsed > IDLE_THRESHOLD;
2424
}
2525

2626
abstract getSchema(): Promise<object>;

redisinsight/api/src/modules/rdi/constants/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ export enum RdiUrl {
1414
Action = 'api/v1/actions',
1515
}
1616

17-
export const IDLE_TRESHOLD = 10 * 60 * 1000; // 10 min
17+
export const IDLE_THRESHOLD = 10 * 60 * 1000; // 10 min
1818
export const RDI_TIMEOUT = 30_000; // 30 sec
19-
export const TOKEN_TRESHOLD = 2 * 60 * 1000; // 2 min
19+
export const TOKEN_THRESHOLD = 2 * 60 * 1000; // 2 min
2020
export const RDI_SYNC_INTERVAL = 5 * 60 * 1_000; // 5 min
2121
export const POLLING_INTERVAL = 1_000;
2222
export const MAX_POLLING_TIME = 2 * 60 * 1000; // 2 min
23+
export const WAIT_BEFORE_POLLING = 1_000;
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
export * from './rdi.client.metadata';
22
export * from './rdi';
3-
export * from './rdi-job';
43
export * from './rdi-pipeline';
54
export * from './rdi-dry-run';
65
export * from './rdi-statistics';

redisinsight/api/src/modules/rdi/models/rdi-job.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import { RdiJob } from 'src/modules/rdi/models/rdi-job';
2-
3-
export enum RdiDeployStatus {
4-
Success = 'success',
5-
Error = 'error',
6-
}
1+
import {
2+
IsObject, IsOptional,
3+
} from 'class-validator';
74

85
export class RdiPipeline {
9-
// todo: defined high-level schema. not sure if we need it at all since we are not going to validate it or we are?
10-
11-
connection: unknown;
12-
13-
jobs: RdiJob[];
6+
@IsOptional()
7+
@IsObject()
8+
// todo add validation
9+
jobs: { [key: string]: object };
10+
11+
@IsOptional()
12+
@IsObject()
13+
config: object;
1414
}

redisinsight/api/src/modules/rdi/providers/rdi.client.provider.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import { RdiClient } from 'src/modules/rdi/client/rdi.client';
2-
import { Injectable } from '@nestjs/common';
2+
import { Injectable, Logger, NotFoundException } from '@nestjs/common';
33
import { RdiClientMetadata } from 'src/modules/rdi/models';
44
import { RdiClientStorage } from 'src/modules/rdi/providers/rdi.client.storage';
55
import { RdiClientFactory } from 'src/modules/rdi/providers/rdi.client.factory';
66
import { RdiRepository } from 'src/modules/rdi/repository/rdi.repository';
7+
import ERROR_MESSAGES from 'src/constants/error-messages';
78

89
@Injectable()
910
export class RdiClientProvider {
11+
private logger: Logger = new Logger('RdiClientProvider');
12+
1013
constructor(
1114
private readonly repository: RdiRepository,
1215
private readonly rdiClientStorage: RdiClientStorage,
@@ -28,6 +31,10 @@ export class RdiClientProvider {
2831
async create(clientMetadata: RdiClientMetadata): Promise<RdiClient> {
2932
const rdi = await this.repository.get(clientMetadata.id);
3033

34+
if (!rdi) {
35+
this.logger.error(`RDI with ${clientMetadata.id} was not Found`);
36+
throw new NotFoundException(ERROR_MESSAGES.INVALID_RDI_INSTANCE_ID);
37+
}
3138
return this.rdiClientFactory.createClient(clientMetadata, rdi);
3239
}
3340

redisinsight/api/src/modules/rdi/providers/rdi.client.storage.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Test, TestingModule } from '@nestjs/testing';
22
import { BadRequestException } from '@nestjs/common';
33
import { generateMockRdiClient } from 'src/__mocks__';
44
import { RdiClientStorage } from 'src/modules/rdi/providers/rdi.client.storage';
5-
import { IDLE_TRESHOLD } from 'src/modules/rdi/constants';
5+
import { IDLE_THRESHOLD } from 'src/modules/rdi/constants';
66
import { SessionMetadata } from 'src/common/models';
77

88
const mockClientMetadata1 = {
@@ -69,7 +69,7 @@ describe('RdiClientStorage', () => {
6969
it('should remove client with exceeded time in idle', async () => {
7070
expect(service['clients'].size).toEqual(4);
7171
const toDelete = service['clients'].get(mockRdiClient1.id);
72-
toDelete['lastUsed'] = Date.now() - IDLE_TRESHOLD - 1;
72+
toDelete['lastUsed'] = Date.now() - IDLE_THRESHOLD - 1;
7373
service['syncClients']();
7474

7575
expect(service['clients'].size).toEqual(3);

redisinsight/api/src/modules/rdi/rdi-pipeline.analytics.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,18 @@ export class RdiPipelineAnalytics extends TelemetryBaseService {
2525
}
2626

2727
sendRdiPipelineFetched(id: string, pipeline: any) {
28-
this.sendEvent(
29-
TelemetryEvents.RdiPipelineDeploymentSucceeded,
30-
{
31-
id,
32-
jobsNumber: Object.keys(pipeline.jobs).length,
33-
source: 'server',
34-
},
35-
);
28+
try {
29+
this.sendEvent(
30+
TelemetryEvents.RdiPipelineDeploymentSucceeded,
31+
{
32+
id,
33+
jobsNumber: pipeline?.jobs ? Object.keys(pipeline.jobs).length : 0,
34+
source: 'server',
35+
},
36+
);
37+
} catch (e) {
38+
// ignore
39+
}
3640
}
3741

3842
sendRdiPipelineFetchFailed(

0 commit comments

Comments
 (0)