Skip to content
Snippets Groups Projects
Select Git revision
  • d2fe4f3b204ce477eaebc522339a8f1c604f14bb
  • without_tipselection default
  • develop protected
  • fix/grafana-local-dashboard
  • wasp
  • fix/dashboard-explorer-freeze
  • master
  • feat/timerqueue
  • test/sync_debug_and_650
  • feat/sync_revamp_inv
  • wip/sync
  • tool/db-recovery
  • portcheck/fix
  • fix/synchronization
  • feat/new-dashboard-analysis
  • feat/refactored-analysis-dashboard
  • feat/new-analysis-dashboard
  • test/demo-prometheus-fpc
  • prometheus_metrics
  • wip/analysis-server
  • merge/fpc-test-value-transfer
  • v0.2.2
  • v0.2.1
  • v0.2.0
  • v0.1.3
  • v0.1.2
  • v0.1.1
  • v0.1.0
28 results

spammer.go

Blame
  • plugin.go NaN GiB
    package gracefulshutdown
    
    import (
    	"os"
    	"os/signal"
    	"strings"
    	"syscall"
    	"time"
    
    	"github.com/iotaledger/hive.go/daemon"
    	"github.com/iotaledger/hive.go/logger"
    	"github.com/iotaledger/hive.go/node"
    )
    
    // maximum amount of time to wait for background processes to terminate. After that the process is killed.
    const WAIT_TO_KILL_TIME_IN_SECONDS = 10
    
    var log = logger.NewLogger("Graceful Shutdown")
    var PLUGIN = node.NewPlugin("Graceful Shutdown", node.Enabled, func(plugin *node.Plugin) {
    	gracefulStop := make(chan os.Signal)
    
    	signal.Notify(gracefulStop, syscall.SIGTERM)
    	signal.Notify(gracefulStop, syscall.SIGINT)
    
    	go func() {
    		<-gracefulStop
    
    		log.Warningf("Received shutdown request - waiting (max %d) to finish processing ...", WAIT_TO_KILL_TIME_IN_SECONDS)
    
    		go func() {
    			start := time.Now()
    			for x := range time.Tick(1 * time.Second) {
    				secondsSinceStart := x.Sub(start).Seconds()
    
    				if secondsSinceStart <= WAIT_TO_KILL_TIME_IN_SECONDS {
    					processList := ""
    					runningBackgroundWorkers := daemon.GetRunningBackgroundWorkers()
    					if len(runningBackgroundWorkers) >= 1 {
    						processList = "(" + strings.Join(runningBackgroundWorkers, ", ") + ") "
    					}
    					log.Warningf("Received shutdown request - waiting (max %d seconds) to finish processing %s...", WAIT_TO_KILL_TIME_IN_SECONDS-int(secondsSinceStart), processList)
    				} else {
    					log.Error("Background processes did not terminate in time! Forcing shutdown ...")
    					os.Exit(1)
    				}
    			}
    		}()
    
    		daemon.Shutdown()
    	}()
    })