-
Notifications
You must be signed in to change notification settings - Fork 570
/
waitForTrainingJobCompletedOrStopped.ts
67 lines (65 loc) · 2.41 KB
/
waitForTrainingJobCompletedOrStopped.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
55
56
57
58
59
60
61
62
63
64
65
66
67
// smithy-typescript generated code
import { checkExceptions, createWaiter, WaiterConfiguration, WaiterResult, WaiterState } from "@aws-sdk/util-waiter";
import { DescribeTrainingJobCommand, DescribeTrainingJobCommandInput } from "../commands/DescribeTrainingJobCommand";
import { SageMakerClient } from "../SageMakerClient";
const checkState = async (client: SageMakerClient, input: DescribeTrainingJobCommandInput): Promise<WaiterResult> => {
let reason;
try {
const result: any = await client.send(new DescribeTrainingJobCommand(input));
reason = result;
try {
const returnComparator = () => {
return result.TrainingJobStatus;
};
if (returnComparator() === "Completed") {
return { state: WaiterState.SUCCESS, reason };
}
} catch (e) {}
try {
const returnComparator = () => {
return result.TrainingJobStatus;
};
if (returnComparator() === "Stopped") {
return { state: WaiterState.SUCCESS, reason };
}
} catch (e) {}
try {
const returnComparator = () => {
return result.TrainingJobStatus;
};
if (returnComparator() === "Failed") {
return { state: WaiterState.FAILURE, reason };
}
} catch (e) {}
} catch (exception) {
reason = exception;
if (exception.name && exception.name == "ValidationException") {
return { state: WaiterState.FAILURE, reason };
}
}
return { state: WaiterState.RETRY, reason };
};
/**
*
* @deprecated Use waitUntilTrainingJobCompletedOrStopped instead. waitForTrainingJobCompletedOrStopped does not throw error in non-success cases.
*/
export const waitForTrainingJobCompletedOrStopped = async (
params: WaiterConfiguration<SageMakerClient>,
input: DescribeTrainingJobCommandInput
): Promise<WaiterResult> => {
const serviceDefaults = { minDelay: 120, maxDelay: 120 };
return createWaiter({ ...serviceDefaults, ...params }, input, checkState);
};
/**
*
* @param params - Waiter configuration options.
* @param input - The input to DescribeTrainingJobCommand for polling.
*/
export const waitUntilTrainingJobCompletedOrStopped = async (
params: WaiterConfiguration<SageMakerClient>,
input: DescribeTrainingJobCommandInput
): Promise<WaiterResult> => {
const serviceDefaults = { minDelay: 120, maxDelay: 120 };
const result = await createWaiter({ ...serviceDefaults, ...params }, input, checkState);
return checkExceptions(result);
};