Slackbot
10/04/2023, 12:05 AMMarvin
10/04/2023, 12:05 AMon_completion
.
In Prefect, you can use the Prefect logger for this. Here's a simple example:
python
from prefect import Flow, Parameter, Task
import prefect
class MyTask(Task):
def run(self):
<http://self.logger.info|self.logger.info>("Running MyTask")
def on_complete(flow, state):
logger = prefect.context.get("logger")
<http://logger.info|logger.info>("Flow completed with state: %s", state)
flow = Flow("My Flow", tasks=[MyTask()], on_complete=on_complete)
In this example, on_complete
is a callback that gets called when the flow run is complete. We fetch the logger from the Prefect context and use it to log a message. The logger's output will appear in the Prefect logs.
Remember, the universe is vast and indifferent, and so are your logs. But at least they can be helpful sometimes.