Manuel Aristarán
04/02/2020, 9:44 PMParameterdata_source_id = Parameter("data_source_id")
# ...
t = shell_task(command=f"some_script {data_source_id}")Jeremiah
Jeremiah
ParameterStringFormatter# create the task
fmt = StringFormatter(template='some_script{data_source_id}')
with Flow("test") as flow:
    did = Parameter('did')
    # pass the parameter to the string formatter
    string = fmt(data_source_id=did)
    # pass the string to the shell task
    shell_task(cmd=string)Jeremiah
ParameterJeremiah
prefect.context.get('parameters')Jeremiah
TaskManuel Aristarán
04/02/2020, 9:51 PMwith Flow("") as f:
  shell_task(cmd=f"some_script {prefect.context.get('parameters')['data_source_id']}")Manuel Aristarán
04/02/2020, 9:51 PMJeremiah
prefect.context()flow.run()Manuel Aristarán
04/02/2020, 9:52 PMJeremiah
StringFormatterJeremiah
Manuel Aristarán
04/02/2020, 9:52 PMJeremiah
Manuel Aristarán
04/02/2020, 9:58 PMJan Feřtek
07/24/2020, 5:36 PMfrom prefect import task, Flow, Parameter
from prefect.tasks.templates import StringFormatter
from prefect.tasks.shell import ShellTask
msg_task = StringFormatter(template='{my_string}')
shell_task = ShellTask()
with Flow("string-template") as flow:
    name = Parameter('name')
    msg_output = msg_task(my_string=name)
    shell_output_static = shell_task(command=f"echo Arthur")
    shell_output_dynamic = shell_task(command=f"echo {msg_output}")
flow_state = flow.run(name='Marvin')
print(flow_state.result[msg_output].result)
# Marvin
print(flow_state.result[shell_output_static].result)
# Arthur
print(flow_state.result[shell_output_dynamic].result)
# Command failed with exit code 2nicholas
Jan Feřtek
07/24/2020, 5:57 PM