Skip to content

Commit f8bbc57

Browse files
Merge branch 'main' into issue/uk-prod-airflow
2 parents c7edd6c + 4187097 commit f8bbc57

File tree

2 files changed

+64
-2
lines changed

2 files changed

+64
-2
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import os
2+
from datetime import datetime, timedelta, timezone
3+
from airflow import DAG
4+
from airflow.providers.amazon.aws.operators.ecs import EcsRunTaskOperator
5+
6+
from airflow.operators.latest_only import LatestOnlyOperator
7+
from utils.slack import on_failure_callback
8+
9+
default_args = {
10+
"owner": "airflow",
11+
"depends_on_past": False,
12+
# the start_date needs to be less than the last cron run
13+
"start_date": datetime.now(tz=timezone.utc) - timedelta(hours=3),
14+
"retries": 2,
15+
"retry_delay": timedelta(minutes=1),
16+
"max_active_runs": 10,
17+
"concurrency": 10,
18+
"max_active_tasks": 10,
19+
}
20+
21+
env = os.getenv("ENVIRONMENT", "development")
22+
subnet = os.getenv("ECS_SUBNET")
23+
security_group = os.getenv("ECS_SECURITY_GROUP")
24+
cluster = f"Nowcasting-{env}"
25+
26+
# Tasks can still be defined in terraform, or defined here
27+
28+
region = "uk"
29+
30+
with DAG(
31+
f"{region}-cloudcasting",
32+
schedule_interval="20,50 * * * *",
33+
default_args=default_args,
34+
concurrency=10,
35+
max_active_tasks=10,
36+
) as dag:
37+
dag.doc_md = "Run Cloudcasting app"
38+
39+
latest_only = LatestOnlyOperator(task_id="latest_only")
40+
41+
cloudcasting_forecast = EcsRunTaskOperator(
42+
task_id=f"{region}-cloudcasting",
43+
task_definition="cloudcasting",
44+
cluster=cluster,
45+
overrides={},
46+
launch_type="FARGATE",
47+
network_configuration={
48+
"awsvpcConfiguration": {
49+
"subnets": [subnet],
50+
"securityGroups": [security_group],
51+
"assignPublicIp": "ENABLED",
52+
},
53+
},
54+
task_concurrency=10,
55+
on_failure_callback=on_failure_callback,
56+
awslogs_group="/aws/ecs/forecast/cloudcasting",
57+
awslogs_stream_prefix="streaming/cloudcasting-forecast",
58+
awslogs_region="eu-west-1",
59+
)
60+
61+
latest_only >> cloudcasting_forecast
62+

terraform/nowcasting/development/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -558,15 +558,15 @@ source = "../../modules/services/ecs_task"
558558
ecs-task_type = "forecast"
559559
ecs-task_execution_role_arn = module.ecs.ecs_task_execution_role_arn
560560
ecs-task_size = {
561-
memory = 2048
561+
memory = 4096
562562
cpu = 1024
563563
}
564564

565565
container-env_vars = [
566566
{ "name" : "AWS_REGION", "value" : var.region },
567567
{ "name" : "ENVIRONMENT", "value" : local.environment },
568568
{ "name" : "LOGLEVEL", "value" : "INFO" },
569-
{ "name" : "OUTPUT_PREDICTION_ZARR_PATH", "value":"s3://${module.s3.s3-sat-bucket.id}/forecast/latest/latest.zarr"},
569+
{ "name" : "OUTPUT_PREDICTION_DIRECTORY", "value":"s3://${module.s3.s3-sat-bucket.id}/cloudcasting_forecast"},
570570
{ "name" : "SATELLITE_ZARR_PATH", "value":"s3://${module.s3.s3-sat-bucket.id}/data/latest/latest.zarr"},
571571
]
572572

0 commit comments

Comments
 (0)