fix: 修正导出桶的时间
This commit is contained in:
parent
9e1c4979c0
commit
0444df3b4c
@ -62,8 +62,8 @@ func (e *Exporter) Start(ctx context.Context) error {
|
|||||||
|
|
||||||
now := time.Now().In(e.loc)
|
now := time.Now().In(e.loc)
|
||||||
// 下一个10分钟边界 + 1分30秒
|
// 下一个10分钟边界 + 1分30秒
|
||||||
next := alignToNextBucketEnd(now, 10).Add(60 * time.Second)
|
next := alignToNextBucketEnd(now, 10).Add(90 * time.Second)
|
||||||
e.logger.Printf("调度: 当前=%s, 下次执行=%s (延迟1分)", now.Format("2006-01-02 15:04:05"), next.Format("2006-01-02 15:04:05"))
|
e.logger.Printf("调度: 当前=%s, 下次执行=%s (延迟1分30秒)", now.Format("2006-01-02 15:04:05"), next.Format("2006-01-02 15:04:05"))
|
||||||
delay := time.Until(next)
|
delay := time.Until(next)
|
||||||
if delay > 0 {
|
if delay > 0 {
|
||||||
timer := time.NewTimer(delay)
|
timer := time.NewTimer(delay)
|
||||||
@ -75,11 +75,9 @@ func (e *Exporter) Start(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 修正:当前时间是21:11:30,应该导出的是21:00:00桶(表示21:00-21:10的数据)
|
// 当前时间在 21:11:xx 时,应导出桶 [21:00, 21:10)
|
||||||
currentTime := time.Now().In(e.loc)
|
currentTime := time.Now().In(e.loc)
|
||||||
// 先找到前一个桶末(如21:10:00)
|
|
||||||
bucketEnd := alignToPrevBucketEnd(currentTime, 10)
|
bucketEnd := alignToPrevBucketEnd(currentTime, 10)
|
||||||
// 再找到对应的桶开始(如21:00:00)
|
|
||||||
bucketStart := bucketEnd.Add(-10 * time.Minute)
|
bucketStart := bucketEnd.Add(-10 * time.Minute)
|
||||||
|
|
||||||
e.logger.Printf("当前时间=%s, 导出桶开始时间=%s, 桶结束时间=%s",
|
e.logger.Printf("当前时间=%s, 导出桶开始时间=%s, 桶结束时间=%s",
|
||||||
@ -344,7 +342,8 @@ func alignToNextBucketEnd(t time.Time, minutes int) time.Time {
|
|||||||
func alignToPrevBucketEnd(t time.Time, minutes int) time.Time {
|
func alignToPrevBucketEnd(t time.Time, minutes int) time.Time {
|
||||||
m := t.Minute()
|
m := t.Minute()
|
||||||
prev := (m / minutes) * minutes
|
prev := (m / minutes) * minutes
|
||||||
return t.Truncate(time.Minute).Add(time.Duration(prev-m) * time.Minute).Add(time.Duration(minutes) * time.Minute)
|
// 返回不超过当前时间的10分钟整点(例如 21:21 -> 21:20)
|
||||||
|
return t.Truncate(time.Minute).Add(time.Duration(prev-m) * time.Minute)
|
||||||
}
|
}
|
||||||
|
|
||||||
func fmtNullFloat(v sql.NullFloat64) string {
|
func fmtNullFloat(v sql.NullFloat64) string {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user