Justin Martin
03/07/2022, 2:34 PM@task
decorator? Here is an extremely simplified version of what i'm doing (See thread).
Am I able to define the run_load_proc function as just a FUnctionTask within the flow without an explicit function? Also, not sure if defining the global SqlServerExecute is a total anti-pattern, let me know. Thanks for all of your help.Kevin Kho
with Flow(..) as flow:
a = get_data() # task that returns 1
task(lambda x: x+1)(a)
I think this will work, but you don’t get task names so I personally don’t like itJustin Martin
03/07/2022, 2:41 PMimport prefect
from prefect import task, Flow
from sqlserver import SqlServerExecute
exec_sql = SqlServerExecute(db_name='FinanceDM', host='fstsqldev', driver='{SQL Server Native Client 11.0}; Trusted_Connection=yes;' commit=True, user='jumartin')
@task
def truncate_table(table_name) -> None:
query=f'truncate table {table_name}’
exec_sql.run(query=query
@task
def run_load_proc(prod) -> None:
query=f'{exec {proc}’
exec_sql.run(query=query)
def main():
with Flow("Load Data") as flow:
delete_table = truncate_table('my_table_name')
run_proc = run_load_proc(proc='dbo.my_proc_name', upstream_tasks=delete_table)
flow.run()
if __name__ == "__main__":
main()
Kevin Kho