[X] I used the GitHub search to find a similar request and didn't find it.
[X] I searched the Prefect documentation for this feature.
Prefect Version
2.x
Describe the current behavior
Currently the prefect engine is loaded as a module - all components of it are implemented as functions directly in the module. State is stored in the module as well. This certainly is the pythonic way of doing singeltons.
The issues is that this makes it hard if someone wants to trigger some action based on the actions of the engine.
So if i want to setup a hook that gets called whenever a flow/task is started i would have to monkey patch the engine. This is best avoided as this requires knowledge of implementation details, making it quite brittle as a consequence.
Describe the proposed behavior
Add add functions to the engine to register callbacks that fire as the engine does a certain actions - like starting a flow.
This callbacks should the get access to the context used in triggering the action.
Example Use
A usecase for this would be to do some custom logging for inputs of flows.
As long as this api is stable it would also be quite straightforward to implement things like an open linage integration.
Hey! I'm interested in doing this during a refactor of the engine (which has definitely outgrown its original simple design) — but it's not going to happen quickly.
First check
Prefect Version
2.x
Describe the current behavior
Currently the prefect engine is loaded as a module - all components of it are implemented as functions directly in the module. State is stored in the module as well. This certainly is the pythonic way of doing singeltons.
The issues is that this makes it hard if someone wants to trigger some action based on the actions of the engine.
So if i want to setup a hook that gets called whenever a flow/task is started i would have to monkey patch the engine. This is best avoided as this requires knowledge of implementation details, making it quite brittle as a consequence.
Describe the proposed behavior
Add add functions to the engine to register callbacks that fire as the engine does a certain actions - like starting a flow.
This callbacks should the get access to the context used in triggering the action.
Example Use
A usecase for this would be to do some custom logging for inputs of flows.
As long as this api is stable it would also be quite straightforward to implement things like an open linage integration.
https://github.com/OpenLineage/OpenLineage/issues/81
Additional context
This might be related of https://github.com/PrefectHQ/prefect/issues/7766 but on a lower level