From 615d96c663c4eba6910d3e6438909e850329c9a5 Mon Sep 17 00:00:00 2001 From: heimoshuiyu Date: Sat, 14 Sep 2024 12:00:10 +0800 Subject: [PATCH] =?UTF-8?q?Fix:=20es=5Fintervals=20=E4=B8=BA=E7=A9=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cucyuqing/cmd/es-sync.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cucyuqing/cmd/es-sync.py b/cucyuqing/cmd/es-sync.py index 8ec6088..3eb2b1a 100644 --- a/cucyuqing/cmd/es-sync.py +++ b/cucyuqing/cmd/es-sync.py @@ -172,7 +172,7 @@ async def sync(): await cur.execute( """ WITH RECURSIVE time_slots AS ( - SELECT date_trunc('hour', now() - interval '1 hour') - interval '1 day' AS start_time + SELECT date_trunc('hour', now() - interval '1 hour') - interval '14 day' AS start_time UNION ALL SELECT start_time + INTERVAL '1 hour' FROM time_slots @@ -193,6 +193,10 @@ async def sync(): ESInterval(start_time=row[0], end_time=row[1]) async for row in cur ] + if not es_intervals: + print("没有待同步时间段,等待下一轮同步") + break + print( f"开始同步 ES 数据,总共 {len(es_intervals)} 个时间段,从 {es_intervals[0].start_time} 到 {es_intervals[-1].end_time}" )