You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.3 KiB
Go

package ept
import (
"context"
"joybuywork/internal/app"
"joybuywork/internal/consts/ckey"
"joybuywork/internal/plugins/export"
"joybuywork/internal/plugins/jsonm"
"fmt"
rp "gits.branchcn.com/backend/microcode/plugins/derivative/progress"
"time"
)
// GetExportHashAndInitProgress 获取导出唯一标识并初始化进度
func GetExportHashAndInitProgress(ctx context.Context) (hs, key string) {
hs = export.BuildHashMark()
key = ckey.ExportKey(hs)
app.NewRedisProgress(ctx, key).CreateProgress()
return
}
// WaitExportResult 等待导出结果,拿到导出结果后,缓存的导出结果会被删除
func WaitExportResult(ctx context.Context, key string) (url, err string) {
progress := app.NewRedisProgress(ctx, key)
defer progress.Release()
for {
select {
case <-ctx.Done():
return
default:
res := progress.GetExportProgress()
if res.Status == rp.StatusSuccess || res.Status == rp.StatusFail {
return res.Content, res.ErrMsg
}
time.Sleep(50 * time.Millisecond)
}
}
}
// PrintExportProgress 打印导出进度
func PrintExportProgress(ctx context.Context, progress *rp.Progress) {
b, _ := jsonm.MarshalToString(progress.GetExportProgress())
app.Logger.Info(ctx, fmt.Sprintf("[%s]当前导出进度数据:%s", progress.Key, b))
}