mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-26 17:24:56 +00:00
[AAE-4295] Add retry api calls for delete descriptor and application
This commit is contained in:
parent
36580f690b
commit
f259b7c940
@ -19,6 +19,7 @@ import { E2eRequestApiHelper } from '../../core/actions/e2e-request-api.helper';
|
||||
import { Logger } from '../../core/utils/logger';
|
||||
import { ResultSetPaging } from '@alfresco/js-api';
|
||||
import { ApiService } from '../../core/actions/api.service';
|
||||
import { ApiUtil } from '../../core/actions/api.util';
|
||||
|
||||
export class Application {
|
||||
|
||||
@ -40,8 +41,25 @@ export class Application {
|
||||
}
|
||||
|
||||
async undeploy(applicationName: string): Promise<any> {
|
||||
await this.requestApiHelper.delete(`${this.endPoint}${applicationName}`);
|
||||
Logger.info(`[Application] Application ${applicationName} was undeployed successfully.`);
|
||||
const isApplicationUndeployed = (response: any) => {
|
||||
if (JSON.stringify(response) === '{}') {
|
||||
Logger.info(`[Application] Application was undeployed successfully`);
|
||||
return true;
|
||||
} else {
|
||||
Logger.warn(`[Application] Application was not undeployed`);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
const apiCall = async () => {
|
||||
try {
|
||||
Logger.info(`[Application] Undeploy application ${applicationName} ...`);
|
||||
return this.requestApiHelper.delete(`${this.endPoint}${applicationName}`);
|
||||
} catch (error) {
|
||||
Logger.error(`[Application] Undeploy application ${applicationName} failed with error: ${error.message}`);
|
||||
}
|
||||
};
|
||||
return ApiUtil.waitForApi(apiCall, isApplicationUndeployed, 10, 3000);
|
||||
}
|
||||
|
||||
async deleteDescriptor(name: string): Promise<void> {
|
||||
|
@ -44,13 +44,26 @@ export class Descriptor {
|
||||
}
|
||||
|
||||
async delete(name: string): Promise<void> {
|
||||
try {
|
||||
await this.retryUntilDescriptorIsInStatus(name, `DescriptorCreated`);
|
||||
await this.requestApiHelper.delete(`${this.endPoint}${name}`);
|
||||
Logger.info(`[Descriptor] Descriptor '${name}' was deleted successfully.`);
|
||||
} catch (error) {
|
||||
Logger.error(`[Descriptor] Delete descriptor ${name} failed with message: ${error.message}`);
|
||||
}
|
||||
const isDescriptorDeleted = (response: any) => {
|
||||
if (JSON.stringify(response) === '{}') {
|
||||
Logger.info(`[Descriptor] Descriptor was deleted successfully`);
|
||||
return true;
|
||||
} else {
|
||||
Logger.warn(`[Descriptor] Descriptor was not deleted`);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
const apiCall = async () => {
|
||||
try {
|
||||
await this.retryUntilDescriptorIsInStatus(name, `DescriptorCreated`);
|
||||
Logger.info(`[Descriptor] Deleting descriptor ${name} ...`);
|
||||
return this.requestApiHelper.delete(`${this.endPoint}${name}`);
|
||||
} catch (error) {
|
||||
Logger.error(`[Descriptor] Delete descriptor ${name} failed with error: ${error.message}`);
|
||||
}
|
||||
};
|
||||
return ApiUtil.waitForApi(apiCall, isDescriptorDeleted, 10, 3000);
|
||||
}
|
||||
|
||||
async get(name: string): Promise<any> {
|
||||
@ -64,8 +77,10 @@ export class Descriptor {
|
||||
|
||||
async retryUntilDescriptorIsInStatus(name: string, expectedStatus: string): Promise<any> {
|
||||
const predicate = (result: { status: string }) => {
|
||||
Logger.info(`[Descriptor] Descriptor ${name} status is: ${result.status}`);
|
||||
return result.status === expectedStatus;
|
||||
};
|
||||
|
||||
const apiCall = async () => this.get(name);
|
||||
|
||||
return ApiUtil.waitForApi(apiCall, predicate);
|
||||
|
Loading…
x
Reference in New Issue
Block a user