forked from prefect-archive/quickstart
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path02_logging.py
More file actions
28 lines (22 loc) · 725 Bytes
/
02_logging.py
File metadata and controls
28 lines (22 loc) · 725 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from prefect import flow, task
from prefect.logging import get_run_logger
import random
@task
def get_customer_ids() -> list[str]:
# Fetch customer IDs from a database or API
return [f"customer{n}" for n in random.choices(range(100), k=50)]
@task
def process_customer(customer_id: str) -> str:
# Process a single customer
logger = get_run_logger()
for _ in range(50):
logger.info(f"Processing customer {customer_id}")
return f"Processed {customer_id}"
@flow
def main() -> list[str]:
customer_ids = get_customer_ids()
# Map the process_customer task across all customer IDs
results = process_customer.map(customer_ids)
return results
if __name__ == "__main__":
main()