Skip to content

Commit 602a7fb

Browse files
committed
#RI-4759 - Display detailed statuses for the progress
1 parent de72c24 commit 602a7fb

File tree

3 files changed

+42
-9
lines changed

3 files changed

+42
-9
lines changed

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

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { v4 as uuidv4 } from 'uuid';
22
import config from 'src/utils/config';
3-
import { CloudJobInfo, CloudJobStatus } from 'src/modules/cloud/job/models/cloud-job-info';
3+
import { CloudJobInfo, CloudJobStatus, CloudJobStep } from 'src/modules/cloud/job/models/cloud-job-info';
44
import { HttpException, Logger } from '@nestjs/common';
55
import { ClassType } from 'class-transformer/ClassTransformer';
66
import { CloudJobAbortedException, wrapCloudJobError } from 'src/modules/cloud/job/exceptions';
77
import { SessionMetadata } from 'src/common/models';
88
import { CloudJobName } from 'src/modules/cloud/job/constants';
99
import { CloudRequestUtm } from 'src/modules/cloud/common/models';
10+
import { debounce } from 'lodash';
1011

1112
const cloudConfig = config.get('cloud');
1213

@@ -31,6 +32,8 @@ export abstract class CloudJob {
3132

3233
protected status = CloudJobStatus.Initializing;
3334

35+
protected step = CloudJobStep.Credentials;
36+
3437
protected error?: HttpException;
3538

3639
protected child?: CloudJob;
@@ -41,18 +44,33 @@ export abstract class CloudJob {
4144

4245
protected dependencies: any;
4346

47+
private readonly debounce: any;
48+
4449
protected constructor(options: CloudJobOptions) {
4550
this.options = options;
4651

4752
if (!this.options.stateCallbacks) {
4853
this.options.stateCallbacks = [];
4954
}
55+
56+
this.debounce = debounce(() => {
57+
try {
58+
(this.options?.stateCallbacks || []).forEach((cb) => {
59+
cb?.(this)?.catch?.(() => {});
60+
});
61+
} catch (e) {
62+
// silently ignore callback
63+
}
64+
}, 1_000, {
65+
maxWait: 1_000,
66+
});
5067
}
5168

5269
public async run() {
5370
try {
5471
this.changeState({
5572
status: CloudJobStatus.Running,
73+
step: CloudJobStep.Initializing,
5674
});
5775

5876
return await this.iteration();
@@ -83,6 +101,7 @@ export abstract class CloudJob {
83101
result: this.result,
84102
error: this.error ? wrapCloudJobError(this.error).getResponse() : undefined,
85103
child: this.child?.getState(),
104+
step: this.step,
86105
};
87106
}
88107

@@ -116,13 +135,8 @@ export abstract class CloudJob {
116135

117136
protected changeState(state = {}) {
118137
Object.entries(state).forEach(([key, value]) => { this[key] = value; });
119-
try {
120-
(this.options?.stateCallbacks || []).forEach((cb) => {
121-
cb?.(this)?.catch?.(() => {});
122-
});
123-
} catch (e) {
124-
// silently ignore callback
125-
}
138+
139+
this.debounce();
126140
}
127141

128142
protected checkSignal() {

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { CreateFreeSubscriptionCloudJob } from 'src/modules/cloud/job/jobs/creat
1010
import { CloudDatabaseCapiService } from 'src/modules/cloud/database/cloud-database.capi.service';
1111
import { WaitForActiveDatabaseCloudJob } from 'src/modules/cloud/job/jobs/wait-for-active-database.cloud-job';
1212
import { CloudJobName } from 'src/modules/cloud/job/constants';
13-
import { CloudJobStatus } from 'src/modules/cloud/job/models';
13+
import { CloudJobStatus, CloudJobStep } from 'src/modules/cloud/job/models';
1414
import {
1515
CloudDatabaseAlreadyExistsFreeException, CloudJobUnexpectedErrorException,
1616
CloudTaskNoResourceIdException,
@@ -54,11 +54,15 @@ export class CreateFreeDatabaseCloudJob extends CloudJob {
5454

5555
this.logger.debug('Generating capi credentials');
5656

57+
this.changeState({ step: CloudJobStep.Credentials });
58+
5759
this.data.capiCredentials = await this.dependencies.cloudUserApiService.getCapiKeys(
5860
this.options.sessionMetadata,
5961
this.options.utm,
6062
);
6163

64+
this.changeState({ step: CloudJobStep.Subscription });
65+
6266
this.logger.debug('Get or create free subscription');
6367

6468
freeSubscription = await this.runChildJob(
@@ -70,6 +74,8 @@ export class CreateFreeDatabaseCloudJob extends CloudJob {
7074

7175
this.checkSignal();
7276

77+
this.changeState({ step: CloudJobStep.Database });
78+
7379
const databases = await this.dependencies.cloudDatabaseCapiService.getDatabases(
7480
this.data.capiCredentials,
7581
{

redisinsight/api/src/modules/cloud/job/models/cloud-job-info.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ export enum CloudJobStatus {
1515
Failed = 'failed',
1616
}
1717

18+
export enum CloudJobStep {
19+
Initializing = 'initializing',
20+
Credentials = 'credentials',
21+
Subscription = 'subscription',
22+
Database = 'database',
23+
}
24+
1825
export class CloudJobInfo {
1926
@ApiProperty({
2027
type: String,
@@ -54,4 +61,10 @@ export class CloudJobInfo {
5461
})
5562
@Expose()
5663
result?: any;
64+
65+
@ApiPropertyOptional({
66+
description: 'Job step',
67+
})
68+
@Expose()
69+
step?: CloudJobStep;
5770
}

0 commit comments

Comments
 (0)