[#414] ir: Switch health status on application state transitions
Set health status to * `UNDEFINED` during Server construction; * `STARTING` on `Server.Start` call; * `READY` after successful `Server.Start` call; * `SHUTTING_DOWN` on `Server.Stop` call. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
567421a9b5
commit
4001ba2967
1 changed files with 12 additions and 1 deletions
|
@ -138,7 +138,14 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
// Start runs all event providers.
|
// Start runs all event providers.
|
||||||
func (s *Server) Start(ctx context.Context, intError chan<- error) error {
|
func (s *Server) Start(ctx context.Context, intError chan<- error) (err error) {
|
||||||
|
s.setHealthStatus(control.HealthStatus_STARTING)
|
||||||
|
defer func() {
|
||||||
|
if err == nil {
|
||||||
|
s.setHealthStatus(control.HealthStatus_READY)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
for _, starter := range s.starters {
|
for _, starter := range s.starters {
|
||||||
if err := starter(); err != nil {
|
if err := starter(); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -223,6 +230,8 @@ func (s *Server) startWorkers(ctx context.Context) {
|
||||||
|
|
||||||
// Stop closes all subscription channels.
|
// Stop closes all subscription channels.
|
||||||
func (s *Server) Stop() {
|
func (s *Server) Stop() {
|
||||||
|
s.setHealthStatus(control.HealthStatus_SHUTTING_DOWN)
|
||||||
|
|
||||||
go s.morphListener.Stop()
|
go s.morphListener.Stop()
|
||||||
go s.mainnetListener.Stop()
|
go s.mainnetListener.Stop()
|
||||||
|
|
||||||
|
@ -259,6 +268,8 @@ func New(ctx context.Context, log *zap.Logger, cfg *viper.Viper) (*Server, error
|
||||||
var err error
|
var err error
|
||||||
server := &Server{log: log}
|
server := &Server{log: log}
|
||||||
|
|
||||||
|
server.setHealthStatus(control.HealthStatus_HEALTH_STATUS_UNDEFINED)
|
||||||
|
|
||||||
// parse notary support
|
// parse notary support
|
||||||
server.feeConfig = config.NewFeeConfig(cfg)
|
server.feeConfig = config.NewFeeConfig(cfg)
|
||||||
server.mainNotaryConfig, server.sideNotaryConfig = parseNotaryConfigs(cfg)
|
server.mainNotaryConfig, server.sideNotaryConfig = parseNotaryConfigs(cfg)
|
||||||
|
|
Loading…
Reference in a new issue