Skip to content
Snippets Groups Projects
Unverified Commit 99a43562 authored by Angelo Capossele's avatar Angelo Capossele Committed by GitHub
Browse files

Add panic if backgroundWorker fails (#444)

* :scream: Add panic if backgroundWorker fails

* :art: Use log.Panicf instead of panic
parent b8f0b053
No related branches found
No related tags found
No related merge requests found
...@@ -130,7 +130,7 @@ func monitorForDesynchronization() { ...@@ -130,7 +130,7 @@ func monitorForDesynchronization() {
} }
}) })
daemon.BackgroundWorker("Desync-Monitor", func(shutdownSignal <-chan struct{}) { if err := daemon.BackgroundWorker("Desync-Monitor", func(shutdownSignal <-chan struct{}) {
gossip.Manager().Events().NeighborRemoved.Attach(monitorPeerCountClosure) gossip.Manager().Events().NeighborRemoved.Attach(monitorPeerCountClosure)
defer gossip.Manager().Events().NeighborRemoved.Detach(monitorPeerCountClosure) defer gossip.Manager().Events().NeighborRemoved.Detach(monitorPeerCountClosure)
messagelayer.Tangle.Events.MessageAttached.Attach(monitorMessageInflowClosure) messagelayer.Tangle.Events.MessageAttached.Attach(monitorMessageInflowClosure)
...@@ -163,7 +163,9 @@ func monitorForDesynchronization() { ...@@ -163,7 +163,9 @@ func monitorForDesynchronization() {
return return
} }
} }
}, shutdown.PrioritySynchronization) }, shutdown.PrioritySynchronization); err != nil {
log.Panicf("Failed to start as daemon: %s", err)
}
} }
// starts a background worker and event handlers to check whether the node is synchronized by first collecting // starts a background worker and event handlers to check whether the node is synchronized by first collecting
...@@ -200,7 +202,7 @@ func monitorForSynchronization() { ...@@ -200,7 +202,7 @@ func monitorForSynchronization() {
synced <- types.Empty{} synced <- types.Empty{}
}) })
daemon.BackgroundWorker("Sync-Monitor", func(shutdownSignal <-chan struct{}) { if err := daemon.BackgroundWorker("Sync-Monitor", func(shutdownSignal <-chan struct{}) {
messagelayer.Tangle.Events.MessageAttached.Attach(initAnchorPointClosure) messagelayer.Tangle.Events.MessageAttached.Attach(initAnchorPointClosure)
defer messagelayer.Tangle.Events.MessageAttached.Detach(initAnchorPointClosure) defer messagelayer.Tangle.Events.MessageAttached.Detach(initAnchorPointClosure)
messagelayer.Tangle.Events.MessageSolid.Attach(checkAnchorPointSolidityClosure) messagelayer.Tangle.Events.MessageSolid.Attach(checkAnchorPointSolidityClosure)
...@@ -228,7 +230,9 @@ func monitorForSynchronization() { ...@@ -228,7 +230,9 @@ func monitorForSynchronization() {
return return
} }
} }
}, shutdown.PrioritySynchronization) }, shutdown.PrioritySynchronization); err != nil {
log.Panicf("Failed to start as daemon: %s", err)
}
} }
// fills up the anchor points with newly attached messages which then are used to determine whether we are synchronized. // fills up the anchor points with newly attached messages which then are used to determine whether we are synchronized.
......
...@@ -37,7 +37,7 @@ func configure(*node.Plugin) { ...@@ -37,7 +37,7 @@ func configure(*node.Plugin) {
func run(*node.Plugin) { func run(*node.Plugin) {
log.Infof("Starting %s ...", PluginName) log.Infof("Starting %s ...", PluginName)
if err := daemon.BackgroundWorker("WebAPI Server", worker, shutdown.PriorityWebAPI); err != nil { if err := daemon.BackgroundWorker("WebAPI Server", worker, shutdown.PriorityWebAPI); err != nil {
log.Errorf("Error starting as daemon: %s", err) log.Panicf("Failed to start as daemon: %s", err)
} }
} }
......
...@@ -6,6 +6,7 @@ import ( ...@@ -6,6 +6,7 @@ import (
"github.com/iotaledger/goshimmer/plugins/issuer" "github.com/iotaledger/goshimmer/plugins/issuer"
"github.com/iotaledger/goshimmer/plugins/webapi" "github.com/iotaledger/goshimmer/plugins/webapi"
"github.com/iotaledger/hive.go/daemon" "github.com/iotaledger/hive.go/daemon"
"github.com/iotaledger/hive.go/logger"
"github.com/iotaledger/hive.go/node" "github.com/iotaledger/hive.go/node"
) )
...@@ -17,15 +18,20 @@ const PluginName = "Spammer" ...@@ -17,15 +18,20 @@ const PluginName = "Spammer"
// Plugin is the plugin instance of the spammer plugin. // Plugin is the plugin instance of the spammer plugin.
var Plugin = node.NewPlugin(PluginName, node.Disabled, configure, run) var Plugin = node.NewPlugin(PluginName, node.Disabled, configure, run)
var log *logger.Logger
func configure(plugin *node.Plugin) { func configure(plugin *node.Plugin) {
log = logger.NewLogger(PluginName)
messageSpammer = spammer.New(issuer.IssuePayload) messageSpammer = spammer.New(issuer.IssuePayload)
webapi.Server.GET("spammer", handleRequest) webapi.Server.GET("spammer", handleRequest)
} }
func run(*node.Plugin) { func run(*node.Plugin) {
_ = daemon.BackgroundWorker("Tangle", func(shutdownSignal <-chan struct{}) { if err := daemon.BackgroundWorker("Tangle", func(shutdownSignal <-chan struct{}) {
<-shutdownSignal <-shutdownSignal
messageSpammer.Shutdown() messageSpammer.Shutdown()
}, shutdown.PrioritySpammer) }, shutdown.PrioritySpammer); err != nil {
log.Panicf("Failed to start as daemon: %s", err)
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment