lucian
07/15/2025, 7:25 AMMarvin
07/15/2025, 7:25 AMMarvin
07/15/2025, 7:27 AMpython
from prefect import task
@task(on_running=lambda task, context: print(f"Task {task.name} is starting!"))
def my_task():
pass
b. Using the events system to emit custom events:
python
from prefect.events import emit_event
@task
def my_task():
emit_event(
event="task-started",
resource={"prefect.resource.id": "my-task"},
payload={"message": "Task is starting"}
)
# task logic here
4. You can also monitor task states through:
- The Prefect UI
- The Prefect API
- State queries in your code
- Prefect's logging system
If you need to track when tasks start, I'd recommend either using state change hooks or emitting custom events depending on your specific use case. Would you like me to elaborate on any of these approaches?
Links:
- Task States Documentation
- Events Documentation