I'm not an expert python developer that's why I'll just outline my steps.
SETUP PART
I created a directory ~/Desktop/airflow for apache-airflow and made
export AIRFLOW_HOME=~/Desktop/airflow
then I created venv using
python3 -m venv ~/Desktop/airflow
the result is
then I made
source bin/activate
pip3 install apache-airflow==1.10.9
airflow initdb
the result is
In my airflow.cfg file I checked dags and plugins directories. I created dags and plugins directories inside $AIRFLOW_HOME/Desktop/airflow
I started airflow webserver and scheduler and made sure that everything works fine.
CUSTOM PLUGIN PART
I found a lot of ways how we can create airflow plugins. I tried all the possible ways. Let's start.
First one is to create a plugin folder inside (first_plugin) a project and then create a python file (first_operator.py)
import logging
from airflow.operators import BaseOperator
from airflow.utils.decorators import apply_defaults
from airflow.plugins_manager import AirflowPlugin
log = logging.getLogger(__name__)
class FirstOperator(BaseOperator):
@apply_defaults
def __init__(self, *args, **kwargs):
super(FirstOperator, self).__init__(*args, **kwargs)
def execute(self, context):
log.info("Hello World!")
class FirstOperatorPlugin(AirflowPlugin):
name = "first_plugin"
operators = [FirstOperator]
it looks like
then I just move my plugin folder (first_plugin) to $AIRFLOW_HOME/DESKTOP/airflow/plugins and restart airflow webserver and scheduler.
Now time to create a custom dag with using my custom operator. How to import your plugin correct is a challenge. There are a lot of possible ways to import custom operators. I'll show what I tried.
- from airflow.operators import FirstOperator - deprecated
- from airflow.operators.first_plugin import FirstOperator
- from airflow.operators.first_operator import FirstOperator
- from first_plugin.first_operator import FirstOperator
None of these ways helped me during importing in Pycharm IDE. For example,
from airflow.operators.first_plugin import FirstOperator
But I'm sure if I ignore the import line and put my custom dag into dags folder it'll work fine. (I tried). Moreover, I decided to check airflow logs (in DEBUG mode).
What logs I see when I restart airflow webserver
I spent 2 days and I still have no any solution. Probably you guys tell me to try other ways. I tried.
https://pybit.es/introduction-airflow.html
All of them are working ways but none of them solves my IDE importing problem.