What’s the Prefectest way to use the value of a `p...
# prefect-community
j
What’s the Prefectest way to use the value of a
prefect.Parameter
in a call to a
prefect.ShellTask
? Would I use a
StringFormatter
task?
z
Hi Jake! I could be missing something here, but is there a reason you wouldn't just pass the parameter to your
ShellTask
the same way you would with any other parameter? E.g.:
Copy code
@task
def print_plus_one(x):
    print(x + 1)

with Flow('Parameterized Flow') as flow:
    x = Parameter('x', default = 2)
    print_plus_one(x=x)
j
My
ShellTask
needs to run
tar -zcvf {output_dir}.tar.gz {output_dir}
so I was hoping I could pass a dynamic value to
output_dir
as a
pf.Parameter
instead of needing to pass the whole command. Does that make sense?
j
StringFormatter
is the way to go then!
c
Another pattern you could use here if you don’t want to introduce a new task is subclassing the
ShellTask
and overriding the
run
method to only accept a parameter value which then formats the command located at
self.command
and passes it to
super().run(command=command)
. Let me know if you’d like me to cook up a code example for this
👍 2