Hi, I'm kind of new to prefect, so it's probably a...
# prefect-server
l
Hi, I'm kind of new to prefect, so it's probably a dumb question, but I wanted to know if anyone has tried to do something similar to me. I created a python class to extend the prefect.Flow. Among other things, it overrides the run function (mainly to enforce a few company rules for logging and to setup the context on runtime for each flow), but now I'm having dificulty running my code on a local agent, since the agent does not call flow.run. Is there a way for me to configure those things on my flow class without needing to create my own FlowRunner?
k
Hey @Leonardo Rocha, would you be able to give me an idea of how you subclassed the Flow? Normally people would add configuration and then call the
super().run()
. Not sure everything will hold well when you move to
flow.register()
though. Maybe you can just add your filter to the Prefect logger?
l
class My_Flow(prefect.Flow):
    
def __init__(self, name, schedule=None, **kwargs):
        
...
        
super(My_Flow, self).__init__(name, schedule, **kwargs)
    
def run(self, **kwargs):
        
...
        
with prefect.context(**context_kwargs):
            
return super(My_Flow, self).run(**kwargs)
    
def add_task(self, task: prefect.core.task.Task) -> prefect.core.task.Task:
        
task = super(My_Flow, self).add_task(task)
        
...
        
return task
k
What are you setting in the context? Is it environment variables?
l
Kind of, I have an internal API that I call on My_Flow.run that provides me with the variables needed on the context for each flow.
k
Is this something that can’t be done with the RunConfigs , you can set environment variables on the Flow through this. You can also set them on the agent and the environment variables will be carried over to the Flow.
l
I'll look into it, thank you very much