"use strict";var _a;Object.defineProperty(exports,"__esModule",{value:!0}),exports.ScheduledTaskBase=void 0;const jsiiDeprecationWarnings=require("../../../.warnings.jsii.js"),JSII_RTTI_SYMBOL_1=Symbol.for("jsii.rtti"),aws_ec2_1=require("../../../aws-ec2"),aws_ecs_1=require("../../../aws-ecs"),aws_events_1=require("../../../aws-events"),aws_events_targets_1=require("../../../aws-events-targets"),core_1=require("../../../core"),constructs_1=require("constructs");class ScheduledTaskBase extends constructs_1.Construct{constructor(scope,id,props){super(scope,id);if(jsiiDeprecationWarnings.aws_cdk_lib_aws_ecs_patterns_ScheduledTaskBaseProps(props),this.cluster=props.cluster||this.getDefaultCluster(this,props.vpc),props.desiredTaskCount!==void 0&&props.desiredTaskCount<1)throw new Error("You must specify a desiredTaskCount greater than 0");this.desiredTaskCount=props.desiredTaskCount||1,this.subnetSelection=props.subnetSelection||{subnetType:aws_ec2_1.SubnetType.PRIVATE},this._securityGroups=props.securityGroups,this.eventRule=new aws_events_1.Rule(this,"ScheduledEventRule",{schedule:props.schedule,ruleName:props.ruleName,enabled:props.enabled})}addTaskDefinitionToEventTarget(taskDefinition){jsiiDeprecationWarnings.aws_cdk_lib_aws_ecs_TaskDefinition(taskDefinition);const eventRuleTarget=new aws_events_targets_1.EcsTask({cluster:this.cluster,taskDefinition,taskCount:this.desiredTaskCount,subnetSelection:this.subnetSelection,securityGroups:this._securityGroups});return this.addTaskAsTarget(eventRuleTarget),eventRuleTarget}addTaskAsTarget(ecsTaskTarget){jsiiDeprecationWarnings.aws_cdk_lib_aws_events_targets_EcsTask(ecsTaskTarget),this.eventRule.addTarget(ecsTaskTarget)}getDefaultCluster(scope,vpc){jsiiDeprecationWarnings.aws_cdk_lib_aws_ec2_IVpc(vpc);const DEFAULT_CLUSTER_ID=`EcsDefaultClusterMnL3mNNYN${vpc?vpc.node.id:""}`,stack=core_1.Stack.of(scope);return stack.node.tryFindChild(DEFAULT_CLUSTER_ID)||new aws_ecs_1.Cluster(stack,DEFAULT_CLUSTER_ID,{vpc})}createAWSLogDriver(prefix){return new aws_ecs_1.AwsLogDriver({streamPrefix:prefix})}}exports.ScheduledTaskBase=ScheduledTaskBase,_a=JSII_RTTI_SYMBOL_1,ScheduledTaskBase[_a]={fqn:"aws-cdk-lib.aws_ecs_patterns.ScheduledTaskBase",version:"2.13.0"};
//# sourceMappingURL=scheduled-task-base.js.map
