Skip to content
This repository was archived by the owner on Mar 27, 2023. It is now read-only.

Commit f05efba

Browse files
committed
using event and event target in order to specify security group; ScheduledFargateTask doesn't support security groups yet
1 parent 6ee8a74 commit f05efba

File tree

3 files changed

+52
-15
lines changed

3 files changed

+52
-15
lines changed

awscdk/awscdk/celery_default.py

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,51 @@ def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
7676
min_capacity=0, max_capacity=2
7777
)
7878

79-
# self.celery_default_queue_asg.scale_on_metric(
80-
# "CeleryDefaultQueueAutoscaling",
81-
# metric=self.default_celery_queue_cloudwatch_metric,
82-
# scaling_steps=[
83-
# app_autoscaling.ScalingInterval(change=1, lower=0),
84-
# app_autoscaling.ScalingInterval(change=-1, lower=1),
85-
# ],
86-
# adjustment_type=app_autoscaling.AdjustmentType.CHANGE_IN_CAPACITY,
87-
# )
88-
# self.celery_default_cloudwatch_monitoring_task = ecs.FargateTaskDefinition(
89-
# self, "CeleryDefaultCloudWatchMonitoringTask"
90-
# )
79+
self.celery_default_queue_asg.scale_on_metric(
80+
"CeleryDefaultQueueAutoscaling",
81+
metric=self.default_celery_queue_cloudwatch_metric,
82+
scaling_steps=[
83+
aas.ScalingInterval(change=1, lower=0),
84+
aas.ScalingInterval(change=-1, lower=1),
85+
],
86+
adjustment_type=aas.AdjustmentType.CHANGE_IN_CAPACITY,
87+
)
88+
89+
self.celery_default_cloudwatch_monitor_task = ecs.FargateTaskDefinition(
90+
self, "CeleryDefaultCloudWatchMonitoringTask"
91+
)
92+
93+
self.celery_default_cloudwatch_monitor_task.add_container(
94+
"CeleryDefaultCWMonitoringTaskContainer",
95+
image=scope.image,
96+
logging=ecs.LogDrivers.aws_logs(
97+
stream_prefix="CeleryDefaultCWMonitoringContainerLogs",
98+
log_retention=logs.RetentionDays.ONE_DAY,
99+
),
100+
environment=scope.variables.regular_variables,
101+
secrets=scope.variables.secret_variables,
102+
command=["python3", "manage.py", "put_celery_cloudwatch_metrics"],
103+
)
104+
105+
self.celery_default_cw_metric_schedule = events.Rule(
106+
self,
107+
"CeleryDefaultCWMetricSchedule",
108+
schedule=events.Schedule.rate(core.Duration.minutes(5)),
109+
targets=[
110+
events_targets.EcsTask(
111+
cluster=scope.cluster,
112+
task_definition=self.celery_default_cloudwatch_monitor_task,
113+
subnet_selection=ec2.SubnetSelection(
114+
subnet_type=ec2.SubnetType.PUBLIC
115+
),
116+
security_group=ec2.SecurityGroup.from_security_group_id(
117+
self,
118+
"CeleryDefaultCWMetricScheduleSG",
119+
security_group_id=scope.vpc.vpc_default_security_group,
120+
),
121+
)
122+
],
123+
)
91124

92125
# self.celery_default_cloudwatch_monitoring_task.add_container(
93126
# "CeleryDefaultCloudWatchMonitoringContainer",

backend/apps/core/management/commands/put_celery_cloudwatch_metrics.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,12 @@ def active_and_reserved_tasks_by_queue_name(self, queue_name):
5656
)
5757

5858
queue_length = r.llen("default")
59-
60-
return active_count + reserved_count + queue_length
59+
total = active_count + reserved_count + queue_length
60+
print(f"Active count: {active_count}")
61+
print(f"Reserved count: {reserved_count}")
62+
print(f"Queue length: {queue_length}")
63+
print(f"Total: {total}")
64+
return total
6165

6266
def publish_queue_metrics(self, queue_names):
6367
print("gathering queue data")

gitlab-ci/aws/cdk.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
variables:
55
ENVIRONMENT: dev
66

7-
quasar build pwa:
7+
.quasar build pwa:
88
image: node:10
99
stage: build
1010
only:

0 commit comments

Comments
 (0)