/
waitForImageDeleted.ts
54 lines (52 loc) · 1.98 KB
/
waitForImageDeleted.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// smithy-typescript generated code
import { checkExceptions, createWaiter, WaiterConfiguration, WaiterResult, WaiterState } from "@aws-sdk/util-waiter";
import { DescribeImageCommand, DescribeImageCommandInput } from "../commands/DescribeImageCommand";
import { SageMakerClient } from "../SageMakerClient";
const checkState = async (client: SageMakerClient, input: DescribeImageCommandInput): Promise<WaiterResult> => {
let reason;
try {
const result: any = await client.send(new DescribeImageCommand(input));
reason = result;
try {
const returnComparator = () => {
return result.ImageStatus;
};
if (returnComparator() === "DELETE_FAILED") {
return { state: WaiterState.FAILURE, reason };
}
} catch (e) {}
} catch (exception) {
reason = exception;
if (exception.name && exception.name == "ResourceNotFoundException") {
return { state: WaiterState.SUCCESS, reason };
}
if (exception.name && exception.name == "ValidationException") {
return { state: WaiterState.FAILURE, reason };
}
}
return { state: WaiterState.RETRY, reason };
};
/**
*
* @deprecated Use waitUntilImageDeleted instead. waitForImageDeleted does not throw error in non-success cases.
*/
export const waitForImageDeleted = async (
params: WaiterConfiguration<SageMakerClient>,
input: DescribeImageCommandInput
): Promise<WaiterResult> => {
const serviceDefaults = { minDelay: 60, maxDelay: 120 };
return createWaiter({ ...serviceDefaults, ...params }, input, checkState);
};
/**
*
* @param params - Waiter configuration options.
* @param input - The input to DescribeImageCommand for polling.
*/
export const waitUntilImageDeleted = async (
params: WaiterConfiguration<SageMakerClient>,
input: DescribeImageCommandInput
): Promise<WaiterResult> => {
const serviceDefaults = { minDelay: 60, maxDelay: 120 };
const result = await createWaiter({ ...serviceDefaults, ...params }, input, checkState);
return checkExceptions(result);
};