Airflow Custom Hooks
For example this function re routes the task to execute in a different queue during retries.
Airflow custom hooks. To make any custom plugin sensor operator available to airflow scheduler we must declare inject our custom plugins in a specific format we will come to that part once we are done writing the. The asf licenses this file to you under the apache license version 2 0 the license. Queue retry queue cluster policies for custom task checks. Built with sphinx using a theme provided by read the docs.
What have you tried so. A hook contains the logic required to perform. The airflow documentation for plugins show that they can be used to do all sorts of customisation of airflow. See the notice file distributed with this work for additional information regarding copyright ownership.
Package contents airflow hooks hooks source airflow hooks airflow importer source airflow hooks integrate plugins source integrate plugins to the context. We will only be focusing on using them to build custom operators that you can then use as tasks in your dags. Share improve this question follow asked nov 28 18 at 13 30. There is however some confusion on the best way to implement them.
If i create custom airflow operator how can i use it in a template which is running on the cloud how to make it available for everyone so that they can use that operator python apache google cloud platform airflow google cloud composer. You should create hook only in the execute method or any method which is called from execute. The asf licenses this file to you under the apache license version 2 0 the license. To mutate the task instance before the task execution you can define a task instance mutation hook function in airflow local settings py that mutates the task instance.
In my custom operators which use my custom hooks i import them like my operator py from hooks my hook import myhook then in my dag files i can do sample dag py from airflow operators plugin name import myoperator this also facilitates testing since the imports within the custom classes are relative to the sub modules within the folder plugins. Source code for airflow hooks mysql hook coding. According to the airflow documentation they can be added using airflow s plugins mechanism. This page uses google analytics to collect statistics.
345 3 3 silver badges 12 12 bronze badges. You may not use this file. I wonder if i can omit the init py file. The two main parts of a custom operator is the hook and the operator.
Logical components of a custom operator plugin. Custom hooks and operators are a powerful way to extend airflow to meet your needs. Utf 8 licensed to the apache software foundation asf under one or more contributor license agreements. The hook retrieves the auth parameters such as username and password from airflow backend and passes the params to the airflow hooks base hook basehook get connection.
Utf 8 licensed to the apache software foundation asf under one or more contributor license agreements. See the notice file distributed with this work for additional information regarding copyright ownership.