Skip to content

Commit

Permalink
Cherry-pick tracelog additions from go-gitea#18732
Browse files Browse the repository at this point in the history
  • Loading branch information
tdesveaux committed Nov 4, 2022
1 parent 97c551e commit c2715ff
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
7 changes: 4 additions & 3 deletions modules/queue/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func getQueueSettings(name string) (setting.QueueSettings, []byte) {

// CreateQueue for name with provided handler and exemplar
func CreateQueue(name string, handle HandlerFunc, exemplar interface{}) Queue {
q, cfg := getQueueSettings(name)
q, cfg := getQueueSettings(string(name))
if len(cfg) == 0 {
return nil
}
Expand All @@ -58,7 +58,7 @@ func CreateQueue(name string, handle HandlerFunc, exemplar interface{}) Queue {
MaxAttempts: q.MaxAttempts,
Config: cfg,
QueueLength: q.QueueLength,
Name: name,
Name: string(name),
}, exemplar)
}
if err != nil {
Expand All @@ -80,7 +80,7 @@ func CreateQueue(name string, handle HandlerFunc, exemplar interface{}) Queue {

// CreateUniqueQueue for name with provided handler and exemplar
func CreateUniqueQueue(name string, handle HandlerFunc, exemplar interface{}) UniqueQueue {
q, cfg := getQueueSettings(name)
q, cfg := getQueueSettings(string(name))
if len(cfg) == 0 {
return nil
}
Expand All @@ -107,6 +107,7 @@ func CreateUniqueQueue(name string, handle HandlerFunc, exemplar interface{}) Un
MaxAttempts: q.MaxAttempts,
Config: cfg,
QueueLength: q.QueueLength,
Name: string(name),
}, exemplar)
}
if err != nil {
Expand Down
10 changes: 5 additions & 5 deletions modules/queue/workerpool.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ func (p *WorkerPool) doWork(ctx context.Context) {
case <-paused:
log.Trace("Worker for Queue %d Pausing", p.qid)
if len(data) > 0 {
log.Trace("Handling: %d data, %v", len(data), data)
log.Trace("Queue[%d] Handling: %d data, %v", p.qid, len(data), data)
if unhandled := p.handle(data...); unhandled != nil {
log.Error("Unhandled Data in queue %d", p.qid)
}
Expand All @@ -523,7 +523,7 @@ func (p *WorkerPool) doWork(ctx context.Context) {
// go back around
case <-ctx.Done():
if len(data) > 0 {
log.Trace("Handling: %d data, %v", len(data), data)
log.Trace("Queue[%d] Handling: %d data, %v", p.qid, len(data), data)
if unhandled := p.handle(data...); unhandled != nil {
log.Error("Unhandled Data in queue %d", p.qid)
}
Expand All @@ -535,7 +535,7 @@ func (p *WorkerPool) doWork(ctx context.Context) {
if !ok {
// the dataChan has been closed - we should finish up:
if len(data) > 0 {
log.Trace("Handling: %d data, %v", len(data), data)
log.Trace("Queue[%d] Handling: %d data, %v", p.qid, len(data), data)
if unhandled := p.handle(data...); unhandled != nil {
log.Error("Unhandled Data in queue %d", p.qid)
}
Expand All @@ -548,7 +548,7 @@ func (p *WorkerPool) doWork(ctx context.Context) {
util.StopTimer(timer)

if len(data) >= p.batchLength {
log.Trace("Handling: %d data, %v", len(data), data)
log.Trace("Queue[%d] Handling: %d data, %v", p.qid, len(data), data)
if unhandled := p.handle(data...); unhandled != nil {
log.Error("Unhandled Data in queue %d", p.qid)
}
Expand All @@ -560,7 +560,7 @@ func (p *WorkerPool) doWork(ctx context.Context) {
case <-timer.C:
delay = time.Millisecond * 100
if len(data) > 0 {
log.Trace("Handling: %d data, %v", len(data), data)
log.Trace("Queue[%d] Handling: %d data, %v", p.qid, len(data), data)
if unhandled := p.handle(data...); unhandled != nil {
log.Error("Unhandled Data in queue %d", p.qid)
}
Expand Down
7 changes: 7 additions & 0 deletions services/pull/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,12 @@ func checkAndUpdateStatus(pr *issues_model.PullRequest) {
}

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

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

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

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

Expand All @@ -346,6 +352,7 @@ func testPR(id int64) {
}
return
}
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)
checkAndUpdateStatus(pr)
}

Expand Down
2 changes: 2 additions & 0 deletions services/pull/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,12 +296,14 @@ func checkConflicts(ctx context.Context, pr *issues_model.PullRequest, gitRepo *
var treeHash string
treeHash, _, err = git.NewCommand(ctx, "write-tree").RunStdString(&git.RunOpts{Dir: tmpBasePath})
if err != nil {
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)
lsfiles, _, _ := git.NewCommand(ctx, "ls-files", "-u").RunStdString(&git.RunOpts{Dir: tmpBasePath})
return false, fmt.Errorf("unable to write unconflicted tree: %w\n`git ls-files -u`:\n%s", err, lsfiles)
}
treeHash = strings.TrimSpace(treeHash)
baseTree, err := gitRepo.GetTree("base")
if err != nil {
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)
return false, err
}
if treeHash == baseTree.ID.String() {
Expand Down
2 changes: 1 addition & 1 deletion services/repository/archiver/archiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ func Init() error {

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

go graceful.GetManager().RunWithShutdownFns(archiverQueue.Run)
Expand Down

0 comments on commit c2715ff

Please sign in to comment.