Hey prefecters... is there a mechanism for mapping...
# ask-community
j
Hey prefecters... is there a mechanism for mapping task args to a map? Specifically trying to set the name of the task... you can see from the example below only the static name seems to work...
Copy code
dirs = ["dir1", "dir2", "dir3"]
commands = [f"rm -rf {d}" for d in dirs]
names = [{"name": f"removing dir {d}"} for d in dirs]

shell = ShellTask()

with Flow as f:
    shell.map(command = commands, task_args={"name": "removing dir"})
    # shell.map(command = commands, task_args={"name": dirs})          # not working
    # shell.map(command = commands, task_args=names)                   # not working

f.run()
Possibly not getting some syntax right. Thanks.
c
Hey Jeremy -- task names are static properties and really only one task is mapped when you map (and the name of the task doesn't change when you map); I think what you're looking for is better represented by task run names. You can provide a callable to your shell task that dynamically generates run names based on things like inputs which should achieve the bookkeeping you are looking for. Check out the docs for the
task_run_name
kwarg on tasks
πŸ‘ 1
upvote 1
z
j
Copy code
dirs = ["dir1", "dir2", "dir3"]
commands = [f"rm -rf {d}" for d in dirs]

shell = ShellTask(task_run_name="removing dir {command}")

with Flow as f:
    shell.map(command = commands)

f.run()
Ah interesting... should I expect something like above to work? Doesn't seem to quite do it πŸ˜›
c
Ah task run names are server-side concepts, so you'll need to run the flow against either a Server API or the Cloud API to see them
j
Ahh I see... is it fair to say there is no easy way to have dynamic named task for mapped tasks when just running via a simple python script (non-server/cloud)?
k
I think so because it’s the backend that injects that.
πŸ‘ 1