fix(office): 延迟导入业务模块并补充 .airflowignore 及 __main__ 保护以解决 DagBag 导入超时

This commit is contained in:
王文艳
2026-10-19 09:38:44 +08:00
parent 0b7caf6a9f
commit fb8f6400be
6 changed files with 68 additions and 37 deletions
+6 -2
View File
@@ -3,11 +3,15 @@
"""
from airflow.providers.standard.operators.bash import BashOperator
from airflow.operators.python import PythonOperator, BranchPythonOperator
from office.rent.base_price import calc
import pendulum
from airflow import DAG
def run_base_rent_calc(**kwargs):
from office.rent.base_price import calc
return calc(**kwargs)
def choose_task(**context):
"""根据 dag_run.conf 决定执行哪个任务"""
conf = context['dag_run'].conf or {}
@@ -50,7 +54,7 @@ with DAG(
# 任务2:写字楼租金计算
t2 = PythonOperator(
task_id='office_base_rent_calc',
python_callable=calc,
python_callable=run_base_rent_calc,
# 🛡️ 已移除 provide_context=True,防止 Airflow 3.3.0 报错崩溃
)
branch_task >> [t1, t2]