Skip to content
This repository was archived by the owner on Aug 23, 2023. It is now read-only.

Commit e4301f5

Browse files
committedDec 15, 2015
use a loop rather then recursion when publishing metricPersist message
1 parent 69aba3a commit e4301f5

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed
 

‎metric_tank/cluster.go

+16-12
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,22 @@ func (msg *PersistMessage) Send() {
7171
if err != nil {
7272
log.Fatal(4, "failed to marshal persistMessage to json.")
7373
}
74-
// This will always return a host. If all hosts are currently marked as dead,
75-
// then all hosts will be reset to alive and we will try them all again. This
76-
// will result in this loop repeating forever until we successfully publish our msg.
77-
hostPoolResponse := hostPool.Get()
78-
p := producers[hostPoolResponse.Host()]
79-
err = p.Publish(*topicNotifyPersist, body)
80-
// Hosts that are marked as dead will be retried after 30seconds. If we published
81-
// successfully, then sending a nil error will mark the host as alive again.
82-
hostPoolResponse.Mark(err)
83-
if err != nil {
84-
log.Warn("publisher marking host %s as faulty due to %s", hostPoolResponse.Host(), err)
85-
msg.Send()
74+
sent := false
75+
for !sent {
76+
// This will always return a host. If all hosts are currently marked as dead,
77+
// then all hosts will be reset to alive and we will try them all again. This
78+
// will result in this loop repeating forever until we successfully publish our msg.
79+
hostPoolResponse := hostPool.Get()
80+
p := producers[hostPoolResponse.Host()]
81+
err = p.Publish(*topicNotifyPersist, body)
82+
// Hosts that are marked as dead will be retried after 30seconds. If we published
83+
// successfully, then sending a nil error will mark the host as alive again.
84+
hostPoolResponse.Mark(err)
85+
if err != nil {
86+
log.Warn("publisher marking host %s as faulty due to %s", hostPoolResponse.Host(), err)
87+
} else {
88+
sent = true
89+
}
8690
}
8791

8892
return

0 commit comments

Comments
 (0)
This repository has been archived.