https://prefect.io logo
Title
g

George Coyne

12/18/2019, 10:23 PM
Hey guys, there was some talk of task looping the other day, I have a similar question. I am converting a lambda. In said lambda one function outputs a list which I then iterate over. What is the prefect-est way to achieve this?
def handler(event, context):
    recipient_list = check_state()
    service = service_account_login()
    completed_samples = []
    for r in recipient_list:
        # message = create_message(recipient=r, email_from=EMAIL_FROM)
        # send_message(service, USER_ID, message)
        <http://logger.info|logger.info>(f"Message sent to {r[3]} for sampleid {r[4]}")
        completed_samples.append(r[4])
    # Write to state table for completed samples
    write_state(completed_samples)
d

Dylan

12/18/2019, 10:34 PM
Hey George! I think you’re looking for https://docs.prefect.io/core/concepts/mapping.html#mapping
that way, each function call for each iterable is turned into a task run that can automatically retry and run in parallel
Let me know if this is helpful @George Coyne 👍
g

George Coyne

12/18/2019, 10:43 PM
Nice! Thanks!