Skip to content

Commit f3b2116

Browse files
committed
fix: simplify the db connection
1 parent 32c86bc commit f3b2116

File tree

1 file changed

+8
-31
lines changed

1 file changed

+8
-31
lines changed

internal/whatsapp/client.go

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -132,42 +132,19 @@ func getDetailedSubscriberData(newsletters []NewsletterInfo) (*NewsletterData, e
132132
}
133133
defer client.Disconnect()
134134

135-
fmt.Println("Waiting for WhatsApp connection and synchronization...")
135+
fmt.Println("Waiting for WhatsApp connection...")
136136
maxWaitTime := 120 * time.Second
137137
timeout := time.After(maxWaitTime)
138-
connectionStable := false
139-
140-
for !connectionStable {
141-
select {
142-
case <-connected:
143-
fmt.Println("Connected! Waiting for synchronization to complete...")
144-
stabilityCheck := time.After(10 * time.Second)
145-
stable := true
146-
147-
stabilityLoop:
148-
for stable {
149-
select {
150-
case <-reconnecting:
151-
fmt.Println("Reconnection detected, waiting for stability...")
152-
stable = false
153-
break stabilityLoop
154-
case <-stabilityCheck:
155-
connectionStable = true
156-
break stabilityLoop
157-
case <-timeout:
158-
return nil, fmt.Errorf("timeout waiting for stable connection")
159-
}
160-
}
161138

162-
case <-reconnecting:
163-
continue
164-
case <-timeout:
165-
return nil, fmt.Errorf("timeout waiting for WhatsApp connection")
166-
}
139+
select {
140+
case <-connected:
141+
fmt.Println("WhatsApp connected! Pausing for 5 seconds to stabilize...")
142+
time.Sleep(5 * time.Second)
143+
case <-timeout:
144+
return nil, fmt.Errorf("timeout waiting for WhatsApp connection")
167145
}
168146

169-
fmt.Println("WhatsApp connection is stable. Fetching newsletter data...")
170-
time.Sleep(2 * time.Second)
147+
fmt.Println("WhatsApp connection established. Fetching newsletter data...")
171148

172149
var updatedNewsletters []NewsletterInfo
173150
var totalSubscribers int

0 commit comments

Comments
 (0)