Make shutdown handling predictable

This commit is contained in:
2015-10-18 03:22:07 +03:00
parent 559886f297
commit d847be21c6
6 changed files with 99 additions and 76 deletions
+3 -3
View File
@@ -15,12 +15,12 @@ type NumberPrinter struct {
// Startup sets up panic handler and starts enqueuing number printing jobs.
func (n *NumberPrinter) Startup() {
n.HandlePanics(func() {
log.Println("Oh, crap! There was a panic, take a look:")
n.HandlePanics(func(err interface{}) {
log.Printf("Oh, crap! There was a panic, take a look: %v", err)
})
n.SystemProcess("Random Number Generator", n.generateNumbers)
n.LimitRate(1, 2*time.Second)
n.SystemProcess("Random Number Generator", n.generateNumbers)
}
// Shutdown is empty due to the lack of cleanup.
+1 -1
View File
@@ -19,10 +19,10 @@ type PriceUpdate struct {
// Startup creates a new subscription for ProductPriceUpdates topic.
func (p *PriceConsumer) Startup() {
p.LimitRate(1, 500*time.Millisecond)
b.Subscribe("ProductPriceUpdates", func(u PriceUpdate) {
log.Printf("Price for %q is now $%.2f", u.Product, u.Amount)
})
p.LimitRate(1, 500*time.Millisecond)
}
// Shutdown is empty because PriceConsumer requires no cleanup upon exiting.