From fb8f6400be76b502591ee00189bd38b758e327ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=96=87=E8=89=B3?= Date: Mon, 19 Oct 2026 09:38:44 +0800 Subject: [PATCH] =?UTF-8?q?fix(office):=20=E5=BB=B6=E8=BF=9F=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=E4=B8=9A=E5=8A=A1=E6=A8=A1=E5=9D=97=E5=B9=B6=E8=A1=A5?= =?UTF-8?q?=E5=85=85=20.airflowignore=20=E5=8F=8A=20=5F=5Fmain=5F=5F=20?= =?UTF-8?q?=E4=BF=9D=E6=8A=A4=E4=BB=A5=E8=A7=A3=E5=86=B3=20DagBag=20?= =?UTF-8?q?=E5=AF=BC=E5=85=A5=E8=B6=85=E6=97=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dags/.airflowignore | 18 +++++++++++++++++- dags/office/dag_office_rent.py | 8 ++++++-- dags/office/dag_office_sell.py | 16 ++++++++++++---- dags/office/rent/price.py | 19 ++++++++++--------- dags/office/sell/fill_price.py | 21 +++++++++++---------- dags/office/sell/price.py | 23 ++++++++++++----------- 6 files changed, 68 insertions(+), 37 deletions(-) diff --git a/dags/.airflowignore b/dags/.airflowignore index fece69f..a8e33c9 100644 --- a/dags/.airflowignore +++ b/dags/.airflowignore @@ -1,9 +1,25 @@ poi/business/* stat/evaluate/* stat/community/* +stats/evaluate/* +stats/community/* +stats/aiprice/* +stats/cityPrice/* +stats/test/* mt/supply/* business/business/* jh/merge/* jh/para/* jh/price/* -db/* \ No newline at end of file +jh/sample/* +db/* +office/rent/* +office/sell/* +shop/rent/* +shop/sell/* +company/company/* +ai/stock/* +price_exponents/region_price_month.py +price_exponents/seaweed_price_month.py +test/* +train/* \ No newline at end of file diff --git a/dags/office/dag_office_rent.py b/dags/office/dag_office_rent.py index 7845c9e..e168dcb 100644 --- a/dags/office/dag_office_rent.py +++ b/dags/office/dag_office_rent.py @@ -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] \ No newline at end of file diff --git a/dags/office/dag_office_sell.py b/dags/office/dag_office_sell.py index 816b524..ad8139e 100644 --- a/dags/office/dag_office_sell.py +++ b/dags/office/dag_office_sell.py @@ -1,13 +1,21 @@ from airflow.providers.standard.operators.bash import BashOperator from airflow.operators.python import PythonOperator, BranchPythonOperator from airflow.operators.empty import EmptyOperator -from office.sell.base_price import calc -from office.sell.fill_base_price import fill_base_price import pendulum from airflow import DAG +def run_base_price_calc(**kwargs): + from office.sell.base_price import calc + return calc(**kwargs) + + +def run_fill_base_price(**kwargs): + from office.sell.fill_base_price import fill_base_price + return fill_base_price(**kwargs) + + def choose_task(**context): """根据 dag_run.conf 决定执行哪个任务""" conf = context['dag_run'].conf or {} @@ -56,14 +64,14 @@ with DAG( # 任务1: 写字楼出售基础价格计算 t1 = PythonOperator( task_id='office_sell_base_price_calc', - python_callable=calc, + python_callable=run_base_price_calc, # 🛡️ 已安全移除 provide_context=True ) # 任务2: 无样本写字楼出售基础价格填充 t2 = PythonOperator( task_id='office_no_sample_sell_base_price_calc', - python_callable=fill_base_price, + python_callable=run_fill_base_price, # 🛡️ 已安全移除 provide_context=True ) diff --git a/dags/office/rent/price.py b/dags/office/rent/price.py index 645c42c..e65062f 100644 --- a/dags/office/rent/price.py +++ b/dags/office/rent/price.py @@ -81,16 +81,17 @@ def calc(city, year_month): log.info(f"{city} {year_month} 均价计算完毕!") -yearmonth = sys.argv[1] if len(sys.argv) > 1 else '' +if __name__ == "__main__": + yearmonth = sys.argv[1] if len(sys.argv) > 1 else '' -if yearmonth == '': - date = dateutils.add_months(datetime.today(), months=-1) - yearmonth = int(dateutils.format_date(date, '%Y%m')) -try: - for city in areautils.get_all_cities(): - calc(city, yearmonth) -except Exception as e: - log.error(e) + if yearmonth == '': + date = dateutils.add_months(datetime.today(), months=-1) + yearmonth = int(dateutils.format_date(date, '%Y%m')) + try: + for city in areautils.get_all_cities(): + calc(city, yearmonth) + except Exception as e: + log.error(e) # # 初始化从2024年9月 # 创建从2024年9月到2024年12月的日期范围 diff --git a/dags/office/sell/fill_price.py b/dags/office/sell/fill_price.py index b6550a4..c3695b3 100644 --- a/dags/office/sell/fill_price.py +++ b/dags/office/sell/fill_price.py @@ -101,17 +101,18 @@ def calc(city, year_month): log.info(f"均价补充完毕!") -yearmonth = sys.argv[1] if len(sys.argv) > 1 else '' +if __name__ == "__main__": + yearmonth = sys.argv[1] if len(sys.argv) > 1 else '' -if yearmonth == '': - date = dateutils.add_months(datetime.today(), months=-1) - yearmonth = int(dateutils.format_date(date, '%Y%m')) -try: - if type(yearmonth) is str: - yearmonth = int(yearmonth) - calc(None, yearmonth) -except Exception as e: - log.error(e) + if yearmonth == '': + date = dateutils.add_months(datetime.today(), months=-1) + yearmonth = int(dateutils.format_date(date, '%Y%m')) + try: + if type(yearmonth) is str: + yearmonth = int(yearmonth) + calc(None, yearmonth) + except Exception as e: + log.error(e) # # 初始化从2024年9月 # 创建从2024年9月到2024年12月的日期范围 diff --git a/dags/office/sell/price.py b/dags/office/sell/price.py index 9b000ee..f2149b3 100644 --- a/dags/office/sell/price.py +++ b/dags/office/sell/price.py @@ -80,18 +80,19 @@ def calc(city, year_month): office_sell_stat_conn.bulk_write(actions) log.info(f"{city} {year_month} 均价计算完毕!") -yearmonth = sys.argv[1] if len(sys.argv) > 1 else '' +if __name__ == "__main__": + yearmonth = sys.argv[1] if len(sys.argv) > 1 else '' -if yearmonth == '': - date = dateutils.add_months(datetime.today(), months=-1) - yearmonth = int(dateutils.format_date(date, '%Y%m')) -try: - if type(yearmonth) is str: - yearmonth = int(yearmonth) - for city in areautils.get_all_cities(): - calc(city, yearmonth) -except Exception as e: - log.error(e) + if yearmonth == '': + date = dateutils.add_months(datetime.today(), months=-1) + yearmonth = int(dateutils.format_date(date, '%Y%m')) + try: + if type(yearmonth) is str: + yearmonth = int(yearmonth) + for city in areautils.get_all_cities(): + calc(city, yearmonth) + except Exception as e: + log.error(e) # # 初始化从2024年9月 # 创建从2024年9月到2024年12月的日期范围