mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Improve queue and logger context (#24924)
Before there was a "graceful function": RunWithShutdownFns, it's mainly for some modules which doesn't support context. The old queue system doesn't work well with context, so the old queues need it. After the queue refactoring, the new queue works with context well, so, use Golang context as much as possible, the `RunWithShutdownFns` could be removed (replaced by RunWithCancel for context cancel mechanism), the related code could be simplified. This PR also fixes some legacy queue-init problems, eg: * typo : archiver: "unable to create codes indexer queue" => "unable to create repo-archive queue" * no nil check for failed queues, which causes unfriendly panic After this PR, many goroutines could have better display name:  
This commit is contained in:
@@ -5,51 +5,8 @@ package graceful
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
)
|
||||
|
||||
// ChannelContext is a context that wraps a channel and error as a context
|
||||
type ChannelContext struct {
|
||||
done <-chan struct{}
|
||||
err error
|
||||
}
|
||||
|
||||
// NewChannelContext creates a ChannelContext from a channel and error
|
||||
func NewChannelContext(done <-chan struct{}, err error) *ChannelContext {
|
||||
return &ChannelContext{
|
||||
done: done,
|
||||
err: err,
|
||||
}
|
||||
}
|
||||
|
||||
// Deadline returns the time when work done on behalf of this context
|
||||
// should be canceled. There is no Deadline for a ChannelContext
|
||||
func (ctx *ChannelContext) Deadline() (deadline time.Time, ok bool) {
|
||||
return deadline, ok
|
||||
}
|
||||
|
||||
// Done returns the channel provided at the creation of this context.
|
||||
// When closed, work done on behalf of this context should be canceled.
|
||||
func (ctx *ChannelContext) Done() <-chan struct{} {
|
||||
return ctx.done
|
||||
}
|
||||
|
||||
// Err returns nil, if Done is not closed. If Done is closed,
|
||||
// Err returns the error provided at the creation of this context
|
||||
func (ctx *ChannelContext) Err() error {
|
||||
select {
|
||||
case <-ctx.done:
|
||||
return ctx.err
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// Value returns nil for all calls as no values are or can be associated with this context
|
||||
func (ctx *ChannelContext) Value(key interface{}) interface{} {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ShutdownContext returns a context.Context that is Done at shutdown
|
||||
// Callers using this context should ensure that they are registered as a running server
|
||||
// in order that they are waited for.
|
||||
|
Reference in New Issue
Block a user