Have recently started to use Airflow for various jobs, trying to get handle on templating.
I was very impressed by EmailOperator, in which you could specify a html_content to be a HTML file, which would then be able to access variables from eg. ti.xcom_pull and put them in proper template places.
I am trying to do something similar with XML template that needs to be saved to file, but the question is how and at which point I should pass params
variable to the rendering, if I want to have the data in that variable available to xml_file template during rendering, eg. via {{ params.xyz }}
?
class CreateXMLFromTemplate(BaseOperator):
template_fields = ('xml_file')
template_ext = ('.xml','.html')
def __init__(
self,
*,
xml_file,
params,
output_file,
**kwargs,
):
super().__init__(**kwargs)
self.xml_file=xml_file
self.params=params
self.output_file=output_file
def execute(self,context):
with open(self.output_file,'w') as F:
F.write(self.xml_file) #<- this has rendered airflow builtin templates ok already
return self.output_file
However, as the rendering is automatic somewhere in BaseOperator, it is not clear, how should I go about having the XML rendered output to be able to take in parameters specified in params variable.