feat(task): attach creator to `user` of the context (#7729)

pull/7754/head
KirCute_ECT 2024-12-30 22:55:09 +08:00 committed by GitHub
parent aa1082a56c
commit 6745dcc139
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 19 additions and 4 deletions

View File

@ -1,13 +1,17 @@
package task
import (
"context"
"github.com/alist-org/alist/v3/internal/model"
"github.com/xhofe/tache"
"sync"
"time"
)
type TaskExtension struct {
tache.Base
ctx context.Context
ctxInitMutex sync.Mutex
Creator *model.User
startTime *time.Time
endTime *time.Time
@ -51,6 +55,17 @@ func (t *TaskExtension) GetTotalBytes() int64 {
return t.totalBytes
}
func (t *TaskExtension) Ctx() context.Context {
if t.ctx == nil {
t.ctxInitMutex.Lock()
if t.ctx == nil {
t.ctx = context.WithValue(t.Base.Ctx(), "user", t.Creator)
}
t.ctxInitMutex.Unlock()
}
return t.ctx
}
type TaskExtensionInfo interface {
tache.TaskWithInfo
GetCreator() *model.User