Skip to content

Commit

Permalink
Merge pull request #113 from anila-intelops/recover/panic
Browse files Browse the repository at this point in the history
panic/recover
  • Loading branch information
vijeyash1 authored Jul 27, 2023
2 parents db26d7e + 39aaa8d commit 5257e6f
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion client/pkg/clients/bridge_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,24 @@ const (
// SubscribeGitBridgeNats subscribes to nats jetstream and calls
// the respective funcs to insert data into clickhouse DB
func (n *NATSContext) SubscribeGitBridgeNats(conn clickhouse.DBInterface) {
n.stream.Subscribe(string(bridgeSubject), func(msg *nats.Msg) {
var sub *nats.Subscription
sub, _ = n.stream.Subscribe(string(bridgeSubject), func(msg *nats.Msg) {
// Recover from a panic
defer func() {
if r := recover(); r != nil {
log.Println("Recovered from panic:", r)

// Acknowledge all messages
for {
msg, err := sub.NextMsg(0)
if err != nil {
break
}
msg.Ack()
}
}
}()

msg.Ack()
gitprovider := msg.Header.Get("GitProvider")
repo := model.GitProvider(gitprovider)
Expand Down

0 comments on commit 5257e6f

Please sign in to comment.