Use a default void stats adapter to avoid redundant conditions
This commit is contained in:
parent
20acbfc8eb
commit
154a1d234b
15
satan.go
15
satan.go
|
@ -64,6 +64,7 @@ const (
|
||||||
// Summon creates a new instance of Satan.
|
// Summon creates a new instance of Satan.
|
||||||
func Summon() *Satan {
|
func Summon() *Satan {
|
||||||
return &Satan{
|
return &Satan{
|
||||||
|
DaemonStats: &stats.Void{},
|
||||||
Logger: log.New(os.Stdout, "[daemons] ", log.LstdFlags),
|
Logger: log.New(os.Stdout, "[daemons] ", log.LstdFlags),
|
||||||
NumWorkers: DefaultNumWorkers,
|
NumWorkers: DefaultNumWorkers,
|
||||||
queue: make(chan *task),
|
queue: make(chan *task),
|
||||||
|
@ -174,20 +175,16 @@ func (s *Satan) processSystemTask(t *task) {
|
||||||
func (s *Satan) processGeneralTask(t *task) {
|
func (s *Satan) processGeneralTask(t *task) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if err := recover(); err != nil {
|
if err := recover(); err != nil {
|
||||||
if s.DaemonStats != nil {
|
s.DaemonStats.Error(t.daemon.base().String())
|
||||||
s.DaemonStats.Error(t.daemon.base().String())
|
|
||||||
}
|
|
||||||
t.daemon.base().handlePanic(err)
|
t.daemon.base().handlePanic(err)
|
||||||
s.Logger.Printf("Daemon %s recovered from a panic\nError: %v\n", t.daemon.base(), err)
|
s.Logger.Printf("Daemon %s recovered from a panic\nError: %v\n", t.daemon.base(), err)
|
||||||
debug.PrintStack()
|
debug.PrintStack()
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
if s.DaemonStats != nil {
|
defer func(start time.Time) {
|
||||||
defer func(start time.Time) {
|
dur := time.Now().Sub(start)
|
||||||
dur := time.Now().Sub(start)
|
s.DaemonStats.Add(t.daemon.base().String(), dur)
|
||||||
s.DaemonStats.Add(t.daemon.base().String(), dur)
|
}(time.Now())
|
||||||
}(time.Now())
|
|
||||||
}
|
|
||||||
|
|
||||||
t.actor() // <--- ACTION STARTS HERE
|
t.actor() // <--- ACTION STARTS HERE
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue