MCPcopy Create free account
hub / github.com/cortexproject/cortex / BasicService

Struct BasicService

pkg/util/services/basic_service.go:49–70  ·  view source on GitHub ↗

BasicService implements contract of Service interface, using three supplied functions: StartingFn, RunningFn and StoppingFn. When service is started, these three functions are called as service transitions to Starting, Running and Stopping state. Since they are called sequentially, they don't need

Source from the content-addressed store, hash-verified

47// * 1. StartingFn, 2. RunningFn, 3. StoppingFn -- this is most common, when StartingFn doesn't return error,
48// service is not stopped and context isn't stopped externally while running StartingFn.
49type BasicService struct {
50 // functions only run, if they are not nil. If functions are nil, service will effectively do nothing
51 // in given state, and go to the next one without any error.
52 startFn StartingFn
53 runningFn RunningFn
54 stoppingFn StoppingFn
55
56 // everything below is protected by this mutex
57 stateMu sync.RWMutex
58 state State
59 failureCase error
60 listeners []chan func(l Listener)
61 serviceName string
62
63 // closed when state reaches Running, Terminated or Failed state
64 runningWaitersCh chan struct{}
65 // closed when state reaches Terminated or Failed state
66 terminatedWaitersCh chan struct{}
67
68 serviceContext context.Context
69 serviceCancel context.CancelFunc
70}
71
72func invalidServiceStateError(state, expected State) error {
73 return fmt.Errorf("invalid service state: %v, expected: %v", state, expected)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected