Skip to content

Commit

Permalink
feat(task): attach creator to user of the context (#7729)
Browse files Browse the repository at this point in the history
  • Loading branch information
KirCute authored Dec 30, 2024
1 parent aa1082a commit 6745dcc
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions internal/task/base.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
package task

import (
"context"
"github.com/alist-org/alist/v3/internal/model"
"github.com/xhofe/tache"
"sync"
"time"
)

type TaskExtension struct {
tache.Base
Creator *model.User
startTime *time.Time
endTime *time.Time
totalBytes int64
ctx context.Context
ctxInitMutex sync.Mutex
Creator *model.User
startTime *time.Time
endTime *time.Time
totalBytes int64
}

func (t *TaskExtension) SetCreator(creator *model.User) {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 6745dcc

Please sign in to comment.