Skip to content

Commit 22cd1cc

Browse files
Updated debug prints
1 parent 621ef77 commit 22cd1cc

File tree

1 file changed

+33
-7
lines changed

1 file changed

+33
-7
lines changed

internal/session/interact.go

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,19 @@ func (m *Manager) ExpireSession(username string) {
101101
continue
102102
}
103103

104-
/* store transaction in PostgreSQL */
105-
if _, err := m.archivalPQ.CreateTransactionPQ(context.Background(), txnPQ); err != nil {
106-
/* log error but continue processing other transactions */
107-
fmt.Printf("Failed to archive transaction %s: %v\n", txResult.ID, err)
104+
/* store transaction in PostgreSQL with retries */
105+
var storeErr error
106+
for retries := 0; retries < 3; retries++ {
107+
if _, err := m.archivalPQ.CreateTransactionPQ(context.Background(), txnPQ); err != nil {
108+
storeErr = err
109+
time.Sleep(time.Second * time.Duration(retries+1))
110+
continue
111+
}
112+
storeErr = nil
113+
break
114+
}
115+
if storeErr != nil {
116+
fmt.Printf("Failed to archive transaction %s after retries: %v\n", txResult.ID, storeErr)
108117
continue
109118
}
110119
}
@@ -121,6 +130,9 @@ func (m *Manager) ExpireSession(username string) {
121130
m.sessionOrder.Remove(session.listElem)
122131
}
123132

133+
/* for debugging */
134+
fmt.Printf("Archiving session ID=%s with status=%q\n", session.ID, session.Status)
135+
124136
/* convert all session parameters to PostgreSQL compatible parameters */
125137
archive, err := ConvertSessionToStoreParams(session)
126138
if err != nil {
@@ -130,9 +142,23 @@ func (m *Manager) ExpireSession(username string) {
130142
return
131143
}
132144

133-
/* store session to the archive */
134-
if _, err := m.archivalPQ.StoreSessionPQ(context.Background(), *archive); err != nil {
135-
fmt.Printf("Failed to archive session: %v\n", err)
145+
/* debug print the archive parameters */
146+
fmt.Printf("Archive parameters - ID: %s, Status: %q, Username: %s\n",
147+
archive.ID, archive.Status, archive.Username)
148+
149+
/* store session to the archive with retries */
150+
var storeErr error
151+
for retries := 0; retries < 3; retries++ {
152+
if _, err := m.archivalPQ.StoreSessionPQ(context.Background(), *archive); err != nil {
153+
storeErr = err
154+
time.Sleep(time.Second * time.Duration(retries+1))
155+
continue
156+
}
157+
storeErr = nil
158+
break
159+
}
160+
if storeErr != nil {
161+
fmt.Printf("Failed to archive session after retries: %v\n", storeErr)
136162
return
137163
}
138164

0 commit comments

Comments
 (0)