mirror of
https://github.com/krau/SaveAny-Bot.git
synced 2026-09-04 23:26:39 +08:00
refactor: update logging messages for transfer task execution and progress tracking
This commit is contained in:
@@ -17,8 +17,8 @@ import (
|
|||||||
|
|
||||||
// Execute implements core.Executable.
|
// Execute implements core.Executable.
|
||||||
func (t *Task) Execute(ctx context.Context) error {
|
func (t *Task) Execute(ctx context.Context) error {
|
||||||
logger := log.FromContext(ctx).WithPrefix(fmt.Sprintf("batch_import[%s]", t.ID))
|
logger := log.FromContext(ctx).WithPrefix(fmt.Sprintf("transfer[%s]", t.ID))
|
||||||
logger.Info("Starting batch import task")
|
logger.Info("Starting transfer task")
|
||||||
t.Progress.OnStart(ctx, t)
|
t.Progress.OnStart(ctx, t)
|
||||||
|
|
||||||
workers := config.C().Workers
|
workers := config.C().Workers
|
||||||
@@ -60,9 +60,9 @@ func (t *Task) Execute(ctx context.Context) error {
|
|||||||
|
|
||||||
err := eg.Wait()
|
err := eg.Wait()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Errorf("Error during batch import processing: %v", err)
|
logger.Errorf("Error during transfer processing: %v", err)
|
||||||
} else {
|
} else {
|
||||||
logger.Info("Batch import task completed successfully")
|
logger.Info("Transfer task completed successfully")
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Progress.OnDone(ctx, t, err)
|
t.Progress.OnDone(ctx, t, err)
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ func NewProgressTracker(messageID int, chatID int64) ProgressTracker {
|
|||||||
func (p *Progress) OnStart(ctx context.Context, info TaskInfo) {
|
func (p *Progress) OnStart(ctx context.Context, info TaskInfo) {
|
||||||
p.start = time.Now()
|
p.start = time.Now()
|
||||||
p.lastUpdatePercent.Store(0)
|
p.lastUpdatePercent.Store(0)
|
||||||
log.FromContext(ctx).Debugf("Batch import task progress tracking started for message %d in chat %d", p.MessageID, p.ChatID)
|
log.FromContext(ctx).Debugf("Transfer task progress tracking started for message %d in chat %d", p.MessageID, p.ChatID)
|
||||||
|
|
||||||
sizeMB := float64(info.TotalSize()) / (1024 * 1024)
|
sizeMB := float64(info.TotalSize()) / (1024 * 1024)
|
||||||
statsText := i18n.T(i18nk.BotMsgTransferStartStats, map[string]any{
|
statsText := i18n.T(i18nk.BotMsgTransferStartStats, map[string]any{
|
||||||
@@ -75,7 +75,10 @@ func (p *Progress) OnStart(ctx context.Context, info TaskInfo) {
|
|||||||
|
|
||||||
ext := tgutil.ExtFromContext(ctx)
|
ext := tgutil.ExtFromContext(ctx)
|
||||||
if ext != nil {
|
if ext != nil {
|
||||||
ext.EditMessage(p.ChatID, req)
|
_, err := ext.EditMessage(p.ChatID, req)
|
||||||
|
if err != nil {
|
||||||
|
log.FromContext(ctx).Errorf("Failed to send progress start message: %s", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,8 +101,8 @@ func (p *Progress) OnProgress(ctx context.Context, info TaskInfo) {
|
|||||||
fmt.Fprintf(&progressText, "%d%%", percent)
|
fmt.Fprintf(&progressText, "%d%%", percent)
|
||||||
progressText.WriteString(i18n.T(i18nk.BotMsgProgressTransferUploadedPrefix, nil))
|
progressText.WriteString(i18n.T(i18nk.BotMsgProgressTransferUploadedPrefix, nil))
|
||||||
fmt.Fprintf(&progressText, "%.2f MB / %.2f MB",
|
fmt.Fprintf(&progressText, "%.2f MB / %.2f MB",
|
||||||
float64(info.Uploaded())/(1024*1024),
|
float64(info.Uploaded())/(1024*1024),
|
||||||
float64(info.TotalSize())/(1024*1024))
|
float64(info.TotalSize())/(1024*1024))
|
||||||
|
|
||||||
if p.start.Unix() > 0 {
|
if p.start.Unix() > 0 {
|
||||||
elapsed := time.Since(p.start)
|
elapsed := time.Since(p.start)
|
||||||
@@ -156,7 +159,7 @@ func (p *Progress) OnProgress(ctx context.Context, info TaskInfo) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *Progress) OnDone(ctx context.Context, info TaskInfo, err error) {
|
func (p *Progress) OnDone(ctx context.Context, info TaskInfo, err error) {
|
||||||
log.FromContext(ctx).Debugf("Batch import task progress tracking done for message %d in chat %d", p.MessageID, p.ChatID)
|
log.FromContext(ctx).Debugf("Transfer task progress tracking done for message %d in chat %d", p.MessageID, p.ChatID)
|
||||||
|
|
||||||
entityBuilder := entity.Builder{}
|
entityBuilder := entity.Builder{}
|
||||||
var resultText strings.Builder
|
var resultText strings.Builder
|
||||||
|
|||||||
Reference in New Issue
Block a user