...

Source file src/golang.conradwood.net/go-easyops/server/health.go

Documentation: golang.conradwood.net/go-easyops/server

     1  package server
     2  
     3  import (
     4  	//	"fmt"
     5  	"golang.conradwood.net/apis/common"
     6  )
     7  
     8  var (
     9  	health = common.Health_READY
    10  )
    11  
    12  /*
    13  Set the health of this service. This is useful for services which have periods where they are unavailable. Typically this is directly after starting, but sometimes also a period where they gather data.
    14  
    15  For a service with a delayed startup, the pattern is as follows:
    16  
    17  		func main() {
    18  		 server.SetHealth(common.Health_STARTING)
    19  	         go do_initialisation()
    20  		}
    21  	        func do_initialisation() {
    22  	            doing_slow_things() // ...
    23  	            server.SetHealth(common.Health_READY)
    24  	        }
    25  */
    26  func SetHealth(h common.Health) error {
    27  	rereg := false
    28  	if h != health {
    29  		rereg = true
    30  	}
    31  	health = h
    32  	if rereg && startup_complete {
    33  		reRegister()
    34  	}
    35  	if len(knownServices) == 0 {
    36  		err := ipc_send_health(nil, h)
    37  		if err != nil {
    38  			return err
    39  		}
    40  	}
    41  	for _, svc := range knownServices {
    42  		err := ipc_send_health(svc, h)
    43  		if err != nil {
    44  			return err
    45  		}
    46  	}
    47  	return nil
    48  
    49  }
    50  
    51  func getHealthString() string {
    52  	s := common.Health_name[int32(health)]
    53  	return s
    54  }
    55  func GetHealth() common.Health {
    56  	return health
    57  }
    58  

View as plain text