mirror of
https://github.com/grafana/grafana.git
synced 2024-11-30 12:44:10 -06:00
6c0752473a
* refactor: tracing service refactoring * refactor: sqlstore to instance service * refactor: sqlstore & registory priority * refactor: sqlstore refactor wip * sqlstore: progress on getting tests to work again * sqlstore: progress on refactoring and getting tests working * sqlstore: connection string fix * fix: not sure why this test is not working and required changing expires * fix: updated grafana-cli
65 lines
1.0 KiB
Go
65 lines
1.0 KiB
Go
package registry
|
|
|
|
import (
|
|
"context"
|
|
"reflect"
|
|
"sort"
|
|
)
|
|
|
|
type Descriptor struct {
|
|
Name string
|
|
Instance Service
|
|
InitPriority Priority
|
|
}
|
|
|
|
var services []*Descriptor
|
|
|
|
func RegisterService(instance Service) {
|
|
services = append(services, &Descriptor{
|
|
Name: reflect.TypeOf(instance).Elem().Name(),
|
|
Instance: instance,
|
|
InitPriority: Low,
|
|
})
|
|
}
|
|
|
|
func Register(descriptor *Descriptor) {
|
|
services = append(services, descriptor)
|
|
}
|
|
|
|
func GetServices() []*Descriptor {
|
|
sort.Slice(services, func(i, j int) bool {
|
|
return services[i].InitPriority > services[j].InitPriority
|
|
})
|
|
|
|
return services
|
|
}
|
|
|
|
type Service interface {
|
|
Init() error
|
|
}
|
|
|
|
// Useful for alerting service
|
|
type CanBeDisabled interface {
|
|
IsDisabled() bool
|
|
}
|
|
|
|
type BackgroundService interface {
|
|
Run(ctx context.Context) error
|
|
}
|
|
|
|
type HasInitPriority interface {
|
|
GetInitPriority() Priority
|
|
}
|
|
|
|
func IsDisabled(srv Service) bool {
|
|
canBeDisabled, ok := srv.(CanBeDisabled)
|
|
return ok && canBeDisabled.IsDisabled()
|
|
}
|
|
|
|
type Priority int
|
|
|
|
const (
|
|
High Priority = 100
|
|
Low Priority = 0
|
|
)
|