236 lines
7.4 KiB
TypeScript
236 lines
7.4 KiB
TypeScript
import type { Construct } from 'constructs';
|
|
import type { CfnJobDefinitionProps } from './batch.generated';
|
|
import type { Duration, IResource } from '../../core';
|
|
import { Resource } from '../../core';
|
|
import type { IJobDefinitionRef, JobDefinitionReference } from '../../interfaces/generated/aws-batch-interfaces.generated';
|
|
/**
|
|
* Represents a JobDefinition
|
|
*/
|
|
export interface IJobDefinition extends IResource, IJobDefinitionRef {
|
|
/**
|
|
* The ARN of this job definition
|
|
*
|
|
* @attribute
|
|
*/
|
|
readonly jobDefinitionArn: string;
|
|
/**
|
|
* The name of this job definition
|
|
*
|
|
* @attribute
|
|
*/
|
|
readonly jobDefinitionName: string;
|
|
/**
|
|
* The default parameters passed to the container
|
|
* These parameters can be referenced in the `command` that
|
|
* you give to the container
|
|
*
|
|
* @see https://docs.aws.amazon.com/batch/latest/userguide/job_definition_parameters.html#parameters
|
|
*
|
|
* @default none
|
|
*/
|
|
readonly parameters?: {
|
|
[key: string]: any;
|
|
};
|
|
/**
|
|
* The number of times to retry a job.
|
|
* The job is retried on failure the same number of attempts as the value.
|
|
*
|
|
* @default 1
|
|
*/
|
|
readonly retryAttempts?: number;
|
|
/**
|
|
* Defines the retry behavior for this job
|
|
*
|
|
* @default - no `RetryStrategy`
|
|
*/
|
|
readonly retryStrategies: RetryStrategy[];
|
|
/**
|
|
* The priority of this Job. Only used in Fairshare Scheduling
|
|
* to decide which job to run first when there are multiple jobs
|
|
* with the same share identifier.
|
|
*
|
|
* @default none
|
|
*/
|
|
readonly schedulingPriority?: number;
|
|
/**
|
|
* The timeout time for jobs that are submitted with this job definition.
|
|
* After the amount of time you specify passes,
|
|
* Batch terminates your jobs if they aren't finished.
|
|
*
|
|
* @default - no timeout
|
|
*/
|
|
readonly timeout?: Duration;
|
|
/**
|
|
* Add a RetryStrategy to this JobDefinition
|
|
*/
|
|
addRetryStrategy(strategy: RetryStrategy): void;
|
|
}
|
|
/**
|
|
* Props common to all JobDefinitions
|
|
*/
|
|
export interface JobDefinitionProps {
|
|
/**
|
|
* The name of this job definition
|
|
*
|
|
* @default - generated by CloudFormation
|
|
*/
|
|
readonly jobDefinitionName?: string;
|
|
/**
|
|
* The default parameters passed to the container
|
|
* These parameters can be referenced in the `command` that
|
|
* you give to the container
|
|
*
|
|
* @see https://docs.aws.amazon.com/batch/latest/userguide/job_definition_parameters.html#parameters
|
|
*
|
|
* @default none
|
|
*/
|
|
readonly parameters?: {
|
|
[key: string]: any;
|
|
};
|
|
/**
|
|
* The number of times to retry a job.
|
|
* The job is retried on failure the same number of attempts as the value.
|
|
*
|
|
* @default 1
|
|
*/
|
|
readonly retryAttempts?: number;
|
|
/**
|
|
* Defines the retry behavior for this job
|
|
*
|
|
* @default - no `RetryStrategy`
|
|
*/
|
|
readonly retryStrategies?: RetryStrategy[];
|
|
/**
|
|
* The priority of this Job. Only used in Fairshare Scheduling
|
|
* to decide which job to run first when there are multiple jobs
|
|
* with the same share identifier.
|
|
*
|
|
* @default none
|
|
*/
|
|
readonly schedulingPriority?: number;
|
|
/**
|
|
* The timeout time for jobs that are submitted with this job definition.
|
|
* After the amount of time you specify passes,
|
|
* Batch terminates your jobs if they aren't finished.
|
|
*
|
|
* @default - no timeout
|
|
*/
|
|
readonly timeout?: Duration;
|
|
/**
|
|
* Specifies whether the previous revision of the job definition is retained in an active status after UPDATE events for the resource.
|
|
*
|
|
* When the property is set to false, the previous revision of the job definition is de-registered after a new revision is created.
|
|
* When the property is set to true, the previous revision of the job definition is not de-registered.
|
|
*
|
|
* @default undefined - AWS Batch default is false
|
|
*/
|
|
readonly skipDeregisterOnUpdate?: boolean;
|
|
}
|
|
/**
|
|
* Define how Jobs using this JobDefinition respond to different exit conditions
|
|
*/
|
|
export declare class RetryStrategy {
|
|
/**
|
|
* Create a new RetryStrategy
|
|
*/
|
|
static of(action: Action, on: Reason): RetryStrategy;
|
|
/**
|
|
* The action to take when the job exits with the Reason specified
|
|
*/
|
|
readonly action: Action;
|
|
/**
|
|
* If the job exits with this Reason it will trigger the specified Action
|
|
*/
|
|
readonly on: Reason;
|
|
constructor(action: Action, on: Reason);
|
|
}
|
|
/**
|
|
* The Action to take when all specified conditions in a RetryStrategy are met
|
|
*/
|
|
export declare enum Action {
|
|
/**
|
|
* The job will not retry
|
|
*/
|
|
EXIT = "EXIT",
|
|
/**
|
|
* The job will retry. It can be retried up to the number of times specified in `retryAttempts`.
|
|
*/
|
|
RETRY = "RETRY"
|
|
}
|
|
/**
|
|
* The corresponding Action will only be taken if *all* of the conditions specified here are met.
|
|
*/
|
|
export interface CustomReason {
|
|
/**
|
|
* A glob string that will match on the job exit code. For example, `'40*'` will match 400, 404, 40123456789012
|
|
*
|
|
* @default - will not match on the exit code
|
|
*/
|
|
readonly onExitCode?: string;
|
|
/**
|
|
* A glob string that will match on the statusReason returned by the exiting job.
|
|
* For example, `'Host EC2*'` indicates that the spot instance has been reclaimed.
|
|
*
|
|
* @default - will not match on the status reason
|
|
*/
|
|
readonly onStatusReason?: string;
|
|
/**
|
|
* A glob string that will match on the reason returned by the exiting job
|
|
* For example, `'CannotPullContainerError*'` indicates that container needed to start the job could not be pulled.
|
|
*
|
|
* @default - will not match on the reason
|
|
*/
|
|
readonly onReason?: string;
|
|
}
|
|
/**
|
|
* Common job exit reasons
|
|
*/
|
|
export declare class Reason {
|
|
/**
|
|
* Will match any non-zero exit code
|
|
*/
|
|
static readonly NON_ZERO_EXIT_CODE: Reason;
|
|
/**
|
|
* Will only match if the Docker container could not be pulled
|
|
*/
|
|
static readonly CANNOT_PULL_CONTAINER: Reason;
|
|
/**
|
|
* Will only match if the Spot instance executing the job was reclaimed
|
|
*/
|
|
static readonly SPOT_INSTANCE_RECLAIMED: Reason;
|
|
/**
|
|
* A custom Reason that can match on multiple conditions.
|
|
* Note that all specified conditions must be met for this reason to match.
|
|
*/
|
|
static custom(customReasonProps: CustomReason): Reason;
|
|
}
|
|
/**
|
|
* Abstract base class for JobDefinitions
|
|
*
|
|
* @internal
|
|
*/
|
|
export declare abstract class JobDefinitionBase extends Resource implements IJobDefinition {
|
|
abstract readonly jobDefinitionArn: string;
|
|
abstract readonly jobDefinitionName: string;
|
|
readonly parameters?: {
|
|
[key: string]: any;
|
|
};
|
|
readonly retryAttempts?: number;
|
|
readonly retryStrategies: RetryStrategy[];
|
|
readonly schedulingPriority?: number;
|
|
readonly timeout?: Duration;
|
|
/**
|
|
* Specifies whether the previous revision of the job definition is retained in an active status after UPDATE events for the resource.
|
|
*
|
|
* @default undefined - AWS Batch default is false
|
|
*/
|
|
readonly skipDeregisterOnUpdate?: boolean;
|
|
get jobDefinitionRef(): JobDefinitionReference;
|
|
constructor(scope: Construct, id: string, props?: JobDefinitionProps);
|
|
addRetryStrategy(strategy: RetryStrategy): void;
|
|
}
|
|
/**
|
|
* @internal
|
|
*/
|
|
export declare function baseJobDefinitionProperties(baseJobDefinition: JobDefinitionBase): CfnJobDefinitionProps;
|