Tim Galvin
12/15/2023, 5:52 AMNamedTuple
or pydantic model with a set of attributes. Being able to do something like:
For example, some use cases could be something like this
from prefect import task, flow
import numpy as np
from flint.context import FieldImageProperties, get_field_image_properties
@task
deg add_image_rms(image_data):
field_image_properties: FieldImageProperties = get_field_image_properties()
field_image_properties.image_rms = np.std(image_data)
@task
def add_frequency(image_header):
field_image_properties: FieldImageProperties = get_field_image_properties()
field_image_proerties.image_frequency = header['FREQ']
@flow
def expensive_image_job():
image_data, image_header = super_expensive_thing()
add_image_properties.submit(image_data)
add_frequency.submit(image_header)
What would be the normal way of implementing something like this, and how would this interact in the prefect flow environment?mira
12/15/2023, 2:13 PMclass User(NamedTuple):
name: str
email: str
@task
def get_users() -> List[User]:
# ...
return [
User(
name="test_user",
email=String.load("test-email").value,
)
]
@flow(retries=3, retry_delay_seconds=30)
def send_newsletters(data: Dict[str, Any], region_code: str) -> None:
# ...
users: List[User] = get_users()
... this works for me 👍Jeremiah
Tim Galvin
12/16/2023, 6:55 AMmira
12/16/2023, 7:55 AM