Adam Brusselback
05/05/2021, 4:25 PMKevin Kho
Kevin Kho
Adam Brusselback
05/05/2021, 4:31 PMKevin Kho
Kevin Kho
Adam Brusselback
05/05/2021, 4:35 PMAdam Brusselback
05/05/2021, 4:37 PMKevin Kho
init
params by passing them to the run
params. For this specific task, yes that is the case that you can’t reconfigure. Yes they do seem locked in I think you’re right. Our goal is to make everything available at runtime with the task library.Kevin Kho
Secret
task
Returns:
- None
Raises:
- ValueError: if query parameter is None or a blank string
- DatabaseError: if exception occurs when executing the query
“”"
if not query:
raise ValueError(“A query string must be provided”)
# connect to database, open cursor
# allow psycopg2 to pass through any exceptions raised
conn = pg.connect(
dbname=db_name,
user=user,
password=password,
host=host,
port=port,
)
# try to execute query
# context manager automatically rolls back failed transactions
try:
with conn, conn.cursor() as cursor:
executed = cursor.execute(query=query, vars=data)
if commit:
conn.commit()
else:
conn.rollback()
return executed
# ensure connection is closed
finally:
conn.close()Kevin Kho
Adam Brusselback
05/05/2021, 4:48 PMKevin Kho