Natalie Landsberg
09/19/2024, 7:55 PM@task(task_run_name="reset-indy-config-{device['name']}")
or is it only possible to do {device}
?jack
09/19/2024, 7:59 PM@task(task_run_name=f"reset-indy-config-{device['name']}")
Natalie Landsberg
09/19/2024, 8:01 PMNate
09/19/2024, 8:50 PMfoo
is at function definition time)
as opposed to a template string (without the f) which is rendered after the task is called, and therefore can be named according to the params it received
In [1]: from prefect import task
In [2]: foo = dict(x=42)
In [3]: @task
...: def t(foo: dict): pass
In [4]: t.with_options(task_run_name=f"{foo['x']}")(dict(x=43))
15:48:32.451 | INFO | Task run '42' - Created task run '42' for task 't'
15:48:32.460 | INFO | Task run '42' - Finished in state Completed()
In [5]: t.with_options(task_run_name="{foo[x]}")(dict(x=43))
15:48:43.996 | INFO | Task run '43' - Created task run '43' for task 't'
15:48:44.001 | INFO | Task run '43' - Finished in state Completed()
Natalie Landsberg
09/19/2024, 8:51 PMNate
09/19/2024, 8:53 PMwith_options
if you don't need to template it differently each time, I just did because I wanted to show the examples side by side with the same underlying task object
if you're always going to template the same way, you'd be free to do this
@task(task_run_name="reset-indy-config-{device[name]}")
Natalie Landsberg
09/19/2024, 8:53 PMNatalie Landsberg
09/19/2024, 8:53 PMNate
09/19/2024, 8:53 PM