Skip to content

Commit

Permalink
fix(ecs-patterns): expose service on queue worker services (#2780)
Browse files Browse the repository at this point in the history
  • Loading branch information
piradeepk authored and rix0rrr committed Jun 7, 2019
1 parent a610017 commit 6d83cb9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import sqs = require('@aws-cdk/aws-sqs');
import cdk = require('@aws-cdk/cdk');

/**
* Properties to define a Query Worker service
* Properties to define a queue worker service
*/
export interface QueueWorkerServiceBaseProps {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import cdk = require('@aws-cdk/cdk');
import { QueueWorkerServiceBase, QueueWorkerServiceBaseProps } from '../base/queue-worker-service-base';

/**
* Properties to define an Ec2 query worker service
* Properties to define an Ec2 queue worker service
*/
export interface Ec2QueueWorkerServiceProps extends QueueWorkerServiceBaseProps {
/**
Expand Down Expand Up @@ -41,9 +41,15 @@ export interface Ec2QueueWorkerServiceProps extends QueueWorkerServiceBaseProps
}

/**
* Class to create an Ec2 query worker service
* Class to create an Ec2 queue worker service
*/
export class Ec2QueueWorkerService extends QueueWorkerServiceBase {

/**
* The ECS service in this construct
*/
public readonly service: ecs.Ec2Service;

constructor(scope: cdk.Construct, id: string, props: Ec2QueueWorkerServiceProps) {
super(scope, id, props);

Expand All @@ -61,11 +67,11 @@ export class Ec2QueueWorkerService extends QueueWorkerServiceBase {

// Create an ECS service with the previously defined Task Definition and configure
// autoscaling based on cpu utilization and number of messages visible in the SQS queue.
const ecsService = new ecs.Ec2Service(this, 'QueueWorkerService', {
this.service = new ecs.Ec2Service(this, 'QueueWorkerService', {
cluster: props.cluster,
desiredCount: this.desiredCount,
taskDefinition
});
this.configureAutoscalingForService(ecsService);
this.configureAutoscalingForService(this.service);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,14 @@ export interface FargateQueueWorkerServiceProps extends QueueWorkerServiceBasePr
}

/**
* Class to create a Fargate query worker service
* Class to create a Fargate queue worker service
*/
export class FargateQueueWorkerService extends QueueWorkerServiceBase {
/**
* The Fargate service in this construct
*/
public readonly service: ecs.FargateService;

constructor(scope: cdk.Construct, id: string, props: FargateQueueWorkerServiceProps) {
super(scope, id, props);

Expand All @@ -65,11 +70,11 @@ export class FargateQueueWorkerService extends QueueWorkerServiceBase {

// Create a Fargate service with the previously defined Task Definition and configure
// autoscaling based on cpu utilization and number of messages visible in the SQS queue.
const fargateService = new ecs.FargateService(this, 'FargateQueueWorkerService', {
this.service = new ecs.FargateService(this, 'FargateQueueWorkerService', {
cluster: props.cluster,
desiredCount: this.desiredCount,
taskDefinition
});
this.configureAutoscalingForService(fargateService);
this.configureAutoscalingForService(this.service);
}
}

0 comments on commit 6d83cb9

Please sign in to comment.