[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

答复: How Airflow import modules as it executes the tasks

I think there might be two ways:

1. Setup the connections via. the Airflow UI:, I guess this could be done in your code also.

2. Put your connection setup into a operator at the begin of your dag

发件人: alireza.khoshkbari@ < alireza.khoshkbari@xxxxxxxxx>
发送时间: 2018年5月16日 1:21
收件人: dev@xxxxxxxxxxxxxxxxxx
主题: How Airflow import modules as it executes the tasks

To start off, here is my project structure:
├── dags
│   ├──
│   ├── core
│   │   ├──
│   │   ├── operators
│   │   │   ├──
│   │   │   ├──
│   │   └── util
│   │       ├──
│   │       ├──
│   ├──

Here is the versions and details of the airflow docker setup:

In my dag in different tasks I'm connecting to db (not Airflow db). I've setup db connection pooling,  I expected that my would be be loaded once across the DagRun. However, in the log I can see that each task imports the module and new db connections made by each and every task. I can see that is loaded in each task by having the line below in"I was loaded {}".format(random.randint(0,100)))

I understand that each operator can technically be run in a separate machine and it does make sense that each task runs sort of independently. However, not sure that if this does apply in case of using LocalExecutor. Now the question is, how I can share the resources (db connections) across tasks using LocalExecutor.