微信小程序页面迁移校验之前 P5任务处理之前
This commit is contained in:
@@ -14,7 +14,7 @@ import multiprocessing as mp
|
||||
import subprocess
|
||||
import sys
|
||||
import time as time_mod
|
||||
from datetime import date, datetime, time, timedelta
|
||||
from datetime import date, datetime, timedelta
|
||||
from pathlib import Path
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
@@ -27,6 +27,7 @@ from tasks.utility.check_cutoff_task import CheckCutoffTask
|
||||
from tasks.dwd.dwd_load_task import DwdLoadTask
|
||||
from tasks.ods.ods_tasks import ENABLED_ODS_CODES
|
||||
from utils.logging_utils import build_log_path, configure_logging
|
||||
from neozqyy_shared.datetime_utils import business_date, business_day_range, now_shanghai
|
||||
|
||||
STEP_TIMEOUT_SEC = 120
|
||||
|
||||
@@ -53,6 +54,7 @@ def _compute_dws_window(
|
||||
if dws_start and dws_end and dws_end < dws_start:
|
||||
raise ValueError("dws_end must be >= dws_start")
|
||||
|
||||
cutoff = int(cfg.get("app.business_day_start_hour", 8))
|
||||
store_id = int(cfg.get("app.store_id"))
|
||||
dsn = cfg["db"]["dsn"]
|
||||
session = cfg["db"].get("session")
|
||||
@@ -67,19 +69,22 @@ def _compute_dws_window(
|
||||
if isinstance(mx, date):
|
||||
dws_start = mx - timedelta(days=max(0, int(rebuild_days)))
|
||||
else:
|
||||
dws_start = (datetime.now(tz).date()) - timedelta(days=max(1, int(bootstrap_days)))
|
||||
# 营业日口径:用 business_date 计算"今天"
|
||||
dws_start = business_date(now_shanghai(), cutoff) - timedelta(days=max(1, int(bootstrap_days)))
|
||||
|
||||
if dws_end is None:
|
||||
dws_end = datetime.now(tz).date()
|
||||
dws_end = business_date(now_shanghai(), cutoff)
|
||||
finally:
|
||||
conn.close()
|
||||
|
||||
start_dt = datetime.combine(dws_start, time.min).replace(tzinfo=tz)
|
||||
# end_dt 取到当天 23:59:59,避免只跑到“当前时刻”的 date() 导致少一天
|
||||
end_dt = datetime.combine(dws_end, time.max).replace(tzinfo=tz)
|
||||
# 营业日口径:窗口边界按 cutoff 小时对齐
|
||||
start_dt = business_day_range(dws_start, cutoff)[0]
|
||||
# end_dt 取到营业日结束(即 dws_end 次日 cutoff 前一秒),覆盖完整营业日
|
||||
end_dt = business_day_range(dws_end, cutoff)[1] - timedelta(seconds=1)
|
||||
return start_dt, end_dt
|
||||
|
||||
|
||||
|
||||
def _run_check_cutoff(cfg: AppConfig, logger: logging.Logger):
|
||||
dsn = cfg["db"]["dsn"]
|
||||
session = cfg["db"].get("session")
|
||||
@@ -99,21 +104,21 @@ def _run_check_cutoff(cfg: AppConfig, logger: logging.Logger):
|
||||
|
||||
|
||||
def _iter_daily_windows(window_start: datetime, window_end: datetime) -> list[tuple[datetime, datetime]]:
|
||||
"""按营业日拆分时间窗口。
|
||||
|
||||
window_start/window_end 已按 cutoff 小时对齐(由 _compute_dws_window 保证)。
|
||||
"""
|
||||
if window_start > window_end:
|
||||
return []
|
||||
tz = window_start.tzinfo
|
||||
windows: list[tuple[datetime, datetime]] = []
|
||||
cur = window_start
|
||||
while cur <= window_end:
|
||||
day_start = datetime.combine(cur.date(), time.min).replace(tzinfo=tz)
|
||||
day_end = datetime.combine(cur.date(), time.max).replace(tzinfo=tz)
|
||||
if day_start < window_start:
|
||||
day_start = window_start
|
||||
if day_end > window_end:
|
||||
day_end = window_end
|
||||
windows.append((day_start, day_end))
|
||||
next_day = cur.date() + timedelta(days=1)
|
||||
cur = datetime.combine(next_day, time.min).replace(tzinfo=tz)
|
||||
# 从 window_start 开始,每次推进 24 小时(一个营业日)
|
||||
cur_start = window_start
|
||||
while cur_start <= window_end:
|
||||
cur_end = cur_start + timedelta(days=1) - timedelta(seconds=1)
|
||||
if cur_end > window_end:
|
||||
cur_end = window_end
|
||||
windows.append((cur_start, cur_end))
|
||||
cur_start = cur_start + timedelta(days=1)
|
||||
return windows
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user