Skip to content

Commit dd810d4

Browse files
author
Thomas Desveaux
committed
Cherry-pick tracelog additions from go-gitea#18732
1 parent 15ab632 commit dd810d4

File tree

5 files changed

+41
-9
lines changed

5 files changed

+41
-9
lines changed

modules/queue/setting.go

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,18 @@ func getQueueSettings(name string) (setting.QueueSettings, []byte) {
3838

3939
// CreateQueue for name with provided handler and exemplar
4040
func CreateQueue(name string, handle HandlerFunc, exemplar interface{}) Queue {
41-
q, cfg := getQueueSettings(name)
41+
found := false
42+
for _, expected := range KnownQueueNames {
43+
if name == expected {
44+
found = true
45+
break
46+
}
47+
}
48+
if !found {
49+
log.Warn("%s is not an expected name for an Queue", name)
50+
}
51+
52+
q, cfg := getQueueSettings(string(name)
4253
if len(cfg) == 0 {
4354
return nil
4455
}
@@ -58,7 +69,7 @@ func CreateQueue(name string, handle HandlerFunc, exemplar interface{}) Queue {
5869
MaxAttempts: q.MaxAttempts,
5970
Config: cfg,
6071
QueueLength: q.QueueLength,
61-
Name: name,
72+
Name: string(name),
6273
}, exemplar)
6374
}
6475
if err != nil {
@@ -80,7 +91,18 @@ func CreateQueue(name string, handle HandlerFunc, exemplar interface{}) Queue {
8091

8192
// CreateUniqueQueue for name with provided handler and exemplar
8293
func CreateUniqueQueue(name string, handle HandlerFunc, exemplar interface{}) UniqueQueue {
83-
q, cfg := getQueueSettings(name)
94+
found := false
95+
for _, expected := range KnownUniqueQueueNames {
96+
if name == expected {
97+
found = true
98+
break
99+
}
100+
}
101+
if !found {
102+
log.Warn("%s is not an expected name for an UniqueQueue", name)
103+
}
104+
105+
q, cfg := getQueueSettings(string(name))
84106
if len(cfg) == 0 {
85107
return nil
86108
}
@@ -107,6 +129,7 @@ func CreateUniqueQueue(name string, handle HandlerFunc, exemplar interface{}) Un
107129
MaxAttempts: q.MaxAttempts,
108130
Config: cfg,
109131
QueueLength: q.QueueLength,
132+
Name: string(name),
110133
}, exemplar)
111134
}
112135
if err != nil {

modules/queue/workerpool.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ func (p *WorkerPool) doWork(ctx context.Context) {
500500
case <-paused:
501501
log.Trace("Worker for Queue %d Pausing", p.qid)
502502
if len(data) > 0 {
503-
log.Trace("Handling: %d data, %v", len(data), data)
503+
log.Trace("Queue[%d] Handling: %d data, %v", p.qid, len(data), data)
504504
if unhandled := p.handle(data...); unhandled != nil {
505505
log.Error("Unhandled Data in queue %d", p.qid)
506506
}
@@ -523,7 +523,7 @@ func (p *WorkerPool) doWork(ctx context.Context) {
523523
// go back around
524524
case <-ctx.Done():
525525
if len(data) > 0 {
526-
log.Trace("Handling: %d data, %v", len(data), data)
526+
log.Trace("Queue[%d] Handling: %d data, %v", p.qid, len(data), data)
527527
if unhandled := p.handle(data...); unhandled != nil {
528528
log.Error("Unhandled Data in queue %d", p.qid)
529529
}
@@ -535,7 +535,7 @@ func (p *WorkerPool) doWork(ctx context.Context) {
535535
if !ok {
536536
// the dataChan has been closed - we should finish up:
537537
if len(data) > 0 {
538-
log.Trace("Handling: %d data, %v", len(data), data)
538+
log.Trace("Queue[%d] Handling: %d data, %v", p.qid, len(data), data)
539539
if unhandled := p.handle(data...); unhandled != nil {
540540
log.Error("Unhandled Data in queue %d", p.qid)
541541
}
@@ -548,7 +548,7 @@ func (p *WorkerPool) doWork(ctx context.Context) {
548548
util.StopTimer(timer)
549549

550550
if len(data) >= p.batchLength {
551-
log.Trace("Handling: %d data, %v", len(data), data)
551+
log.Trace("Queue[%d] Handling: %d data, %v", p.qid, len(data), data)
552552
if unhandled := p.handle(data...); unhandled != nil {
553553
log.Error("Unhandled Data in queue %d", p.qid)
554554
}
@@ -560,7 +560,7 @@ func (p *WorkerPool) doWork(ctx context.Context) {
560560
case <-timer.C:
561561
delay = time.Millisecond * 100
562562
if len(data) > 0 {
563-
log.Trace("Handling: %d data, %v", len(data), data)
563+
log.Trace("Queue[%d] Handling: %d data, %v", p.qid, len(data), data)
564564
if unhandled := p.handle(data...); unhandled != nil {
565565
log.Error("Unhandled Data in queue %d", p.qid)
566566
}

services/pull/check.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,12 @@ func checkAndUpdateStatus(pr *issues_model.PullRequest) {
155155
}
156156

157157
if !has {
158+
log.Trace("Updating PR[%d] in %d: Status:%d Conflicts:%s Protected:%s", pr.ID, pr.BaseRepoID, pr.Status, pr.ConflictedFiles, pr.ChangedProtectedFiles)
158159
if err := pr.UpdateColsIfNotMerged("merge_base", "status", "conflicted_files", "changed_protected_files"); err != nil {
159160
log.Error("Update[%d]: %v", pr.ID, err)
160161
}
162+
} else {
163+
log.Trace("Not updating PR[%d] in %d as still in the queue", pr.ID, pr.BaseRepoID)
161164
}
162165
}
163166

@@ -329,12 +332,15 @@ func testPR(id int64) {
329332
log.Error("GetPullRequestByID[%d]: %v", id, err)
330333
return
331334
}
335+
log.Trace("Testing PR[%d] in %d", pr.ID, pr.BaseRepoID)
332336

333337
if pr.HasMerged {
338+
log.Trace("PR[%d] in %d: already merged", pr.ID, pr.BaseRepoID)
334339
return
335340
}
336341

337342
if manuallyMerged(ctx, pr) {
343+
log.Trace("PR[%d] in %d: manually merged", pr.ID, pr.BaseRepoID)
338344
return
339345
}
340346

@@ -346,6 +352,7 @@ func testPR(id int64) {
346352
}
347353
return
348354
}
355+
log.Trace("PR[%d] in %d: patch tested new Status:%d ConflictedFiles:%s ChangedProtectedFiles:%s", pr.ID, pr.BaseRepoID, pr.Status, pr.ConflictedFiles, pr.ChangedProtectedFiles)
349356
checkAndUpdateStatus(pr)
350357
}
351358

services/pull/patch.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,12 +296,14 @@ func checkConflicts(ctx context.Context, pr *issues_model.PullRequest, gitRepo *
296296
var treeHash string
297297
treeHash, _, err = git.NewCommand(ctx, "write-tree").RunStdString(&git.RunOpts{Dir: tmpBasePath})
298298
if err != nil {
299+
log.Debug("Unable to write unconflicted tree for PR[%d] %s/%s#%d. Error: %v", pr.ID, pr.BaseRepo.OwnerName, pr.BaseRepo.Name, pr.Index, err)
299300
lsfiles, _, _ := git.NewCommand(ctx, "ls-files", "-u").RunStdString(&git.RunOpts{Dir: tmpBasePath})
300301
return false, fmt.Errorf("unable to write unconflicted tree: %w\n`git ls-files -u`:\n%s", err, lsfiles)
301302
}
302303
treeHash = strings.TrimSpace(treeHash)
303304
baseTree, err := gitRepo.GetTree("base")
304305
if err != nil {
306+
log.Debug("Unable to get base tree for PR[%d] %s/%s#%d. Error: %v", pr.ID, pr.BaseRepo.OwnerName, pr.BaseRepo.Name, pr.Index, err)
305307
return false, err
306308
}
307309
if treeHash == baseTree.ID.String() {

services/repository/archiver/archiver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ func Init() error {
317317

318318
archiverQueue = queue.CreateUniqueQueue("repo-archive", handler, new(ArchiveRequest))
319319
if archiverQueue == nil {
320-
return errors.New("unable to create codes indexer queue")
320+
return errors.New("unable to create repo archiver queue")
321321
}
322322

323323
go graceful.GetManager().RunWithShutdownFns(archiverQueue.Run)

0 commit comments

Comments
 (0)