Skip to content

Commit 8e547ae

Browse files
AmirAllayarovSofteqArtem
andauthored
#RI - 5239 - fix import db job (#2870)
* #RI - 5239 - fix import db job --------- Co-authored-by: Artem <[email protected]>
1 parent c72e518 commit 8e547ae

File tree

9 files changed

+65
-18
lines changed

9 files changed

+65
-18
lines changed

redisinsight/api/src/modules/cloud/job/dto/import-database.cloud-job.data.dto.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ApiProperty } from '@nestjs/swagger';
2-
import { IsNotEmpty, IsNumber } from 'class-validator';
2+
import { IsNotEmpty, IsNumber, IsString } from 'class-validator';
33

44
export class ImportDatabaseCloudJobDataDto {
55
@ApiProperty({
@@ -17,4 +17,20 @@ export class ImportDatabaseCloudJobDataDto {
1717
@IsNumber()
1818
@IsNotEmpty()
1919
databaseId: number;
20+
21+
@ApiProperty({
22+
description: 'Subscription region',
23+
type: String,
24+
})
25+
@IsString()
26+
@IsNotEmpty()
27+
region: string;
28+
29+
@ApiProperty({
30+
description: 'Subscription provider',
31+
type: String,
32+
})
33+
@IsString()
34+
@IsNotEmpty()
35+
provider: string;
2036
}

redisinsight/api/src/modules/cloud/job/exceptions/cloud-database-already-exists-free.exception.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { CustomErrorCodes } from 'src/constants';
55
export class CloudDatabaseAlreadyExistsFreeException extends HttpException {
66
constructor(
77
message = ERROR_MESSAGES.CLOUD_DATABASE_ALREADY_EXISTS_FREE,
8-
options?: HttpExceptionOptions & { subscriptionId?: number, databaseId?: number },
8+
options?: HttpExceptionOptions & { subscriptionId?: number, databaseId?: number, region?: string, provider?: string },
99
) {
1010
const response = {
1111
message,
@@ -15,6 +15,8 @@ export class CloudDatabaseAlreadyExistsFreeException extends HttpException {
1515
resource: {
1616
subscriptionId: options?.subscriptionId,
1717
databaseId: options?.databaseId,
18+
region: options?.region,
19+
provider: options?.provider,
1820
},
1921
};
2022

redisinsight/api/src/modules/cloud/job/jobs/cloud-job.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ export class CloudJobOptions {
2424
stateCallbacks?: ((self: CloudJob) => any)[] = [];
2525

2626
name?: CloudJobName;
27+
28+
child?: boolean;
2729
}
2830

2931
export abstract class CloudJob {
@@ -57,18 +59,22 @@ export abstract class CloudJob {
5759
}
5860

5961
this.debounce = debounce(() => {
60-
try {
61-
(this.options?.stateCallbacks || []).forEach((cb) => {
62-
cb?.(this)?.catch?.(() => {});
63-
});
64-
} catch (e) {
65-
// silently ignore callback
66-
}
62+
this.triggerChangeStateCallbacks();
6763
}, 1_000, {
6864
maxWait: 2_000,
6965
});
7066
}
7167

68+
private triggerChangeStateCallbacks() {
69+
try {
70+
(this.options?.stateCallbacks || []).forEach((cb) => {
71+
cb?.(this)?.catch?.(() => {});
72+
});
73+
} catch (e) {
74+
// silently ignore callback
75+
}
76+
}
77+
7278
public async run() {
7379
try {
7480
this.changeState({
@@ -127,8 +133,9 @@ export abstract class CloudJob {
127133
return new TargetJob(
128134
{
129135
...this.options,
130-
stateCallbacks: [() => this.changeState()],
131136
...options,
137+
stateCallbacks: [() => this.changeState()],
138+
child: true,
132139
},
133140
data,
134141
this.dependencies,
@@ -154,7 +161,11 @@ export abstract class CloudJob {
154161
protected changeState(state = {}) {
155162
Object.entries(state).forEach(([key, value]) => { this[key] = value; });
156163

157-
this.debounce();
164+
if (this.options.child) {
165+
this.triggerChangeStateCallbacks();
166+
} else {
167+
this.debounce();
168+
}
158169
}
159170

160171
protected checkSignal() {

redisinsight/api/src/modules/cloud/job/jobs/create-free-subscription-and-database.cloud-job.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { CloudCapiKeyService } from 'src/modules/cloud/capi-key/cloud-capi-key.s
1212
import { CloudSubscription } from 'src/modules/cloud/subscription/models';
1313

1414
export class CreateFreeSubscriptionAndDatabaseCloudJob extends CloudJob {
15-
protected name = CloudJobName.CreateFreeDatabase;
15+
protected name = CloudJobName.CreateFreeSubscriptionAndDatabase;
1616

1717
constructor(
1818
readonly options: CloudJobOptions,

redisinsight/api/src/modules/cloud/job/jobs/create-free-subscription.cloud-job.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ export class CreateFreeSubscriptionCloudJob extends CloudJob {
7070
throw new CloudDatabaseAlreadyExistsFreeException(undefined, {
7171
subscriptionId: freeSubscription.id,
7272
databaseId: databases[0].databaseId,
73+
region: freeSubscription?.region,
74+
provider: freeSubscription?.provider,
7375
});
7476
}
7577

redisinsight/api/src/modules/cloud/job/jobs/import-free-database.cloud-job.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ import { CloudCapiKeyService } from 'src/modules/cloud/capi-key/cloud-capi-key.s
1717
const cloudConfig = config.get('cloud');
1818

1919
export class ImportFreeDatabaseCloudJob extends CloudJob {
20-
protected name = CloudJobName.CreateFreeDatabase;
20+
protected name = CloudJobName.ImportFreeDatabase;
2121

2222
constructor(
2323
readonly options: CloudJobOptions,
2424
private readonly data: {
2525
subscriptionId: number,
2626
databaseId: number,
27+
region: string,
28+
provider: string,
2729
},
2830
protected readonly dependencies: {
2931
cloudDatabaseCapiService: CloudDatabaseCapiService,
@@ -84,7 +86,11 @@ export class ImportFreeDatabaseCloudJob extends CloudJob {
8486
timeout: cloudConfig.cloudDatabaseConnectionTimeout,
8587
});
8688

87-
this.result = { resourceId: database.id };
89+
this.result = {
90+
resourceId: database.id,
91+
region: this.data?.region,
92+
provider: this.data?.provider,
93+
};
8894

8995
this.changeState({ status: CloudJobStatus.Finished });
9096

redisinsight/ui/src/components/oauth/oauth-jobs/OAuthJobs.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { get } from 'lodash'
66
import { CloudJobStatus, CloudJobName, CloudJobStep } from 'uiSrc/electron/constants'
77
import { fetchInstancesAction } from 'uiSrc/slices/instances/instances'
88
import { createFreeDbJob, createFreeDbSuccess, oauthCloudJobSelector, oauthCloudSelector, setJob } from 'uiSrc/slices/oauth/cloud'
9+
import { CloudImportDatabaseResources } from 'uiSrc/slices/interfaces/cloud'
910
import { addErrorNotification, addInfiniteNotification, removeInfiniteNotification } from 'uiSrc/slices/app/notifications'
1011
import { parseCloudOAuthError } from 'uiSrc/utils'
1112
import { INFINITE_MESSAGES, InfiniteMessagesIds } from 'uiSrc/components/notifications/components'
@@ -43,13 +44,13 @@ const OAuthJobs = () => {
4344

4445
const errorCode = get(error, 'errorCode', 0) as CustomErrorCodes
4546
const subscriptionId = get(error, 'resource.subscriptionId', 0)
46-
const databaseId = get(error, 'resource.databaseId', 0)
47+
const resources = get(error, 'resource', {}) as CloudImportDatabaseResources
4748
// eslint-disable-next-line sonarjs/no-nested-switch
4849
switch (errorCode) {
4950
case CustomErrorCodes.CloudDatabaseAlreadyExistsFree:
5051
dispatch(addInfiniteNotification(
5152
INFINITE_MESSAGES.DATABASE_EXISTS(
52-
() => importDatabase(subscriptionId, databaseId),
53+
() => importDatabase(resources),
5354
closeImportDatabase,
5455
)
5556
))
@@ -77,13 +78,13 @@ const OAuthJobs = () => {
7778
}
7879
}, [status, error, step, result, showProgress])
7980

80-
const importDatabase = (subscriptionId: number, databaseId: number) => {
81+
const importDatabase = (resources: CloudImportDatabaseResources) => {
8182
sendEventTelemetry({
8283
event: TelemetryEvent.CLOUD_IMPORT_EXISTING_DATABASE,
8384
})
8485
dispatch(createFreeDbJob({
8586
name: CloudJobName.ImportFreeDatabase,
86-
resources: { subscriptionId, databaseId },
87+
resources,
8788
onSuccessAction: () => {
8889
dispatch(removeInfiniteNotification(InfiniteMessagesIds.databaseExists))
8990
dispatch(addInfiniteNotification(INFINITE_MESSAGES.PENDING_CREATE_DB(CloudJobStep.Credentials)))

redisinsight/ui/src/slices/interfaces/cloud.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ export interface StateAppOAuth {
3838
agreement: boolean
3939
}
4040

41+
export interface CloudImportDatabaseResources {
42+
subscriptionId: number,
43+
databaseId?: number
44+
region: string
45+
provider?: string
46+
}
47+
4148
export interface Region {
4249
provider: string
4350
regions: string[]

redisinsight/ui/src/slices/oauth/cloud.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,8 @@ export function createFreeDbJob({
315315
planId?: number,
316316
databaseId?: number,
317317
subscriptionId?: number,
318+
region?: string,
319+
provider?: string,
318320
}
319321
onSuccessAction?: () => void,
320322
onFailAction?: () => void

0 commit comments

Comments
 (0)