https://prefect.io logo
Title
j

Jake Schmidt

01/07/2020, 7:58 PM
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

Zachary Hughes

01/07/2020, 9:25 PM
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.:
@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

Jake Schmidt

01/07/2020, 10:16 PM
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

Jeremiah

01/08/2020, 12:30 AM
StringFormatter
is the way to go then!
c

Chris White

01/08/2020, 1:38 AM
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