Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
added capacity_provider_strategy to ecs variables
Browse files Browse the repository at this point in the history
  • Loading branch information
jeanluciano committed Apr 9, 2024
1 parent c1042d3 commit daa9a24
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
21 changes: 19 additions & 2 deletions prefect_aws/workers/ecs_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@
from pydantic import VERSION as PYDANTIC_VERSION

if PYDANTIC_VERSION.startswith("2."):
from pydantic.v1 import Field, root_validator
from pydantic.v1 import BaseModel, Field, root_validator
else:
from pydantic import Field, root_validator
from pydantic import Field, root_validator, BaseModel

from slugify import slugify
from tenacity import retry, stop_after_attempt, wait_fixed, wait_random
Expand Down Expand Up @@ -367,6 +367,16 @@ def network_configuration_requires_vpc_id(cls, values: dict) -> dict:
return values


class CapacityProvider(BaseModel):
"""
The capacity provider strategy to use when running the task.
"""

capacity_provider: str
weight: int
base: int


class ECSVariables(BaseVariables):
"""
Variables for templating an ECS job.
Expand Down Expand Up @@ -425,6 +435,13 @@ class ECSVariables(BaseVariables):
),
)
)
capacity_provider_strategy: Optional[List[CapacityProvider]] = Field(
default=None,
description=(
"The capacity provider strategy to use when running the task. This is only"
"If a capacityProviderStrategy is specified, we will omit the launchType"
),
)
image: Optional[str] = Field(
default=None,
description=(
Expand Down
12 changes: 4 additions & 8 deletions tests/workers/test_ecs_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2020,15 +2020,11 @@ async def test_user_defined_environment_variables_in_task_definition_template(
async def test_user_defined_capacity_provider_strategy(
aws_credentials: AwsCredentials, flow_run: FlowRun
):
configuration = await construct_configuration_with_job_template(
template_overrides=dict(
task_run_request={
"capacityProviderStrategy": [
{"base": 0, "weight": 1, "capacityProvider": "r6i.large"},
]
},
),
configuration = await construct_configuration(
aws_credentials=aws_credentials,
capacity_provider_strategy=[
{"base": 0, "weight": 1, "capacityProvider": "r6i.large"}
],
)

assert "launchType" not in configuration.task_run_request
Expand Down

0 comments on commit daa9a24

Please sign in to comment.