Skip to content

Commit ef90faf

Browse files
committed
Run heavy processing tasks in the same server cluster
1 parent fddae2a commit ef90faf

File tree

7 files changed

+11
-144
lines changed

7 files changed

+11
-144
lines changed

backend/pycon/tasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def launch_heavy_processing_worker():
2727
if settings.ENVIRONMENT == "local":
2828
return
2929

30-
cluster_name = f"pythonit-{settings.ENVIRONMENT}-heavy-processing-worker"
30+
cluster_name = f"pythonit-{settings.ENVIRONMENT}"
3131
ecs_client = boto3.client("ecs", region_name=settings.AWS_REGION_NAME)
3232

3333
response = ecs_client.list_tasks(cluster=cluster_name, desiredStatus="RUNNING")

infrastructure/applications/applications.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ module "pycon_backend" {
2626
security_group_id = module.cluster.security_group_id
2727
server_ip = module.cluster.server_ip
2828
logs_group_name = module.cluster.logs_group_name
29+
iam_role_arn = module.cluster.iam_role_arn
2930

3031
providers = {
3132
aws = aws

infrastructure/applications/cluster/iam.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,7 @@ data "aws_iam_policy_document" "server_role_policy" {
7979
effect = "Allow"
8080
}
8181
}
82+
83+
output "iam_role_arn" {
84+
value = aws_iam_role.server.arn
85+
}

infrastructure/applications/pycon_backend/variables.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ variable "cluster_id" {}
99
variable "security_group_id" {}
1010
variable "server_ip" {}
1111
variable "logs_group_name" {}
12+
variable "iam_role_arn" {}

infrastructure/applications/pycon_backend/worker_heavy_processing.tf

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,11 @@
1-
resource "aws_ecs_cluster" "heavy_processing_worker" {
2-
name = "pythonit-${terraform.workspace}-heavy-processing-worker"
3-
4-
setting {
5-
name = "containerInsights"
6-
value = "enabled"
7-
}
8-
}
9-
10-
resource "aws_cloudwatch_log_group" "heavy_processing_worker_logs" {
11-
name = "/ecs/pythonit-${terraform.workspace}-heavy-processing-worker"
12-
retention_in_days = 7
13-
}
14-
151
resource "aws_ecs_task_definition" "heavy_processing_worker" {
162
family = "pythonit-${terraform.workspace}-heavy-processing-worker"
173
requires_compatibilities = ["FARGATE"]
184
cpu = 4096
195
memory = 16384
206
network_mode = "awsvpc"
21-
execution_role_arn = aws_iam_role.worker.arn
22-
task_role_arn = aws_iam_role.worker.arn
7+
execution_role_arn = var.iam_role_arn
8+
task_role_arn = var.iam_role_arn
239

2410
ephemeral_storage {
2511
size_in_gib = 21
@@ -62,9 +48,9 @@ resource "aws_ecs_task_definition" "heavy_processing_worker" {
6248
logConfiguration = {
6349
logDriver = "awslogs"
6450
options = {
65-
"awslogs-group" = aws_cloudwatch_log_group.heavy_processing_worker_logs.name
51+
"awslogs-group" = var.logs_group_name
6652
"awslogs-region" = "eu-central-1"
67-
"awslogs-stream-prefix" = "ecs"
53+
"awslogs-stream-prefix" = "heavy-processing-worker"
6854
}
6955
}
7056

infrastructure/applications/pycon_backend/worker_role.tf

Lines changed: 0 additions & 111 deletions
This file was deleted.

infrastructure/applications/pycon_backend/worker_security.tf

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)