riccardo bernardi
03/19/2024, 1:55 PMMarvin
03/19/2024, 1:56 PMshell
prefect config set PREFECT_API_URL="<http://127.0.0.1:4200/api>"
This is necessary when running Prefect inside a container. (Prefect Docs)
2. Local SQLite Database and Dashboard: Use the local SQLite database (~/.prefect/prefect.db
) to inspect flow runs after you start the Prefect server using prefect server start
. You can also use the local UI dashboard to monitor your flows. (Blog Post)
3. Code Debugging: As for debugging the code, you can write your tasks and flows as normal Python functions and then execute them. At this stage, you can include print statements or use Python's built-in debugger (pdb
) to step through your code.
Here is a basic example of a Prefect flow with tasks that can be run and debugged locally:
python
from prefect import flow, task
@task(task_run_name="Adding {x} and {y}")
def add(x: int, y: int) -> int:
"""just a python function with a fancy hat on!"""
return x + y
@flow
def my_flow():
"""tasks must be called in the flow to be executed (at this time)"""
first_result = add(1, 2)
second_result = add(first_result, first_result)
return add(first_result, second_result)
if __name__ == "__main__":
# run the flow
my_flow()
# you can run tasks' functions directly outside of a flow if you want
# but it won't be tracked by Prefect, it's just a normal function
assert add.fn(1, 2) == 3
In the flow my_flow
, the add
task is executed. You can debug this task by running it directly using the syntax add.fn(arg1, arg2)
which won't be tracked by Prefect, allowing you to test and debug the function logic directly. (Example Code)
Remember to tailor your debugging procedures to your specific development environment's details and preferences.riccardo bernardi
03/19/2024, 1:58 PMNate
03/19/2024, 3:08 PMNate
03/19/2024, 3:08 PMpython my_flow.py
Nate
03/19/2024, 3:08 PM