Add check for liveness
License: MIT Signed-off-by: Jakub Sztandera <kubuxu@protocol.ai>
This commit is contained in:
		
							parent
							
								
									0b2718a4af
								
							
						
					
					
						commit
						09341d0440
					
				@ -76,6 +76,8 @@ func GetTips(ctx context.Context, api api.FullNode, lastHeight uint64) (<-chan *
 | 
				
			|||||||
	go func() {
 | 
						go func() {
 | 
				
			||||||
		defer close(chmain)
 | 
							defer close(chmain)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							ping := time.Tick(30 * time.Second)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		for {
 | 
							for {
 | 
				
			||||||
			select {
 | 
								select {
 | 
				
			||||||
			case changes := <-notif:
 | 
								case changes := <-notif:
 | 
				
			||||||
@ -97,6 +99,18 @@ func GetTips(ctx context.Context, api api.FullNode, lastHeight uint64) (<-chan *
 | 
				
			|||||||
						chmain <- change.Val
 | 
											chmain <- change.Val
 | 
				
			||||||
					}
 | 
										}
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
 | 
								case <-ping:
 | 
				
			||||||
 | 
									log.Print("Running health check")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									cctx, cancel := context.WithTimeout(ctx, 5*time.Second)
 | 
				
			||||||
 | 
									if _, err := api.ID(cctx); err != nil {
 | 
				
			||||||
 | 
										log.Print("Health check failed")
 | 
				
			||||||
 | 
										return
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									cancel()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									log.Print("Node online")
 | 
				
			||||||
			case <-ctx.Done():
 | 
								case <-ctx.Done():
 | 
				
			||||||
				return
 | 
									return
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user