fix: align business reports and record task migration progress
This commit is contained in:
@@ -2,6 +2,7 @@ package business
|
||||
|
||||
import (
|
||||
"context"
|
||||
"kra/pkg/task"
|
||||
"math/big"
|
||||
"sort"
|
||||
"strconv"
|
||||
@@ -103,13 +104,35 @@ func (uc *ReportBuildUsecase) Run(ctx context.Context, kind ReportBuildKind, per
|
||||
if finish.Before(begin) {
|
||||
return ErrAnalyticsDateOrder
|
||||
}
|
||||
task.Logf(ctx, "报表类型=%s;日期区间=%s 至 %s", kind, begin.Format("2006-01-02"), finish.Format("2006-01-02"))
|
||||
completed, totalRows, totalKeys := 0, 0, 0
|
||||
defer func() {
|
||||
task.Logf(ctx, "已提交日期=%d;汇总行=%d;身份键=%d", completed, totalRows, totalKeys)
|
||||
}()
|
||||
for day := begin; !day.After(finish); day = day.AddDate(0, 0, 1) {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := uc.repo.Rebuild(ctx, kind, day, func(input *ReportInput) ([]*ReportBuiltRow, error) { return compileReport(kind, input) }); err != nil {
|
||||
started := time.Now()
|
||||
registers, actives, payments, rowCount, keyCount := 0, 0, 0, 0, 0
|
||||
if err := uc.repo.Rebuild(ctx, kind, day, func(input *ReportInput) ([]*ReportBuiltRow, error) {
|
||||
registers, actives, payments = len(input.Registers), len(input.Actives), len(input.Payments)
|
||||
rows, err := compileReport(kind, input)
|
||||
rowCount = len(rows)
|
||||
for _, row := range rows {
|
||||
for _, keys := range row.Keys {
|
||||
keyCount += len(keys)
|
||||
}
|
||||
}
|
||||
return rows, err
|
||||
}); err != nil {
|
||||
task.Logf(ctx, "日期=%s 未提交:%v", day.Format("2006-01-02"), err)
|
||||
return err
|
||||
}
|
||||
completed++
|
||||
totalRows += rowCount
|
||||
totalKeys += keyCount
|
||||
task.Logf(ctx, "日期=%s 已提交;原始注册=%d,活跃=%d,充值=%d;汇总行=%d,身份键=%d;耗时=%d ms", day.Format("2006-01-02"), registers, actives, payments, rowCount, keyCount, time.Since(started).Milliseconds())
|
||||
if day.Before(finish) {
|
||||
if err := uc.pause(ctx); err != nil {
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user