Fix: es_intervals 为空

This commit is contained in:
2024-09-14 12:00:10 +08:00
parent 2d5eae2a18
commit 615d96c663

View File

@@ -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}"
)