Skip to content

Commit 464f5a0

Browse files
Updated main.go for archival support and expiry
1 parent c15237d commit 464f5a0

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

cmd/laclm/main.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,11 @@ func exec() error {
118118
func run(ctx context.Context) error {
119119
var (
120120
err error
121-
wg sync.WaitGroup
121+
wg sync.WaitGroup
122122
)
123123

124124
/* RULE: complete backend system must initiate before http server starts */
125-
125+
126126
/* DATABASE CONNECTIONS MUST BE MADE BEFORE SCHEDULER STARTS */
127127
logRedisClient, err := redis.NewRedisClient(
128128
config.BackendConfig.Database.TransactionLogRedis.Address,
@@ -143,15 +143,15 @@ func run(ctx context.Context) error {
143143
)
144144

145145
connPQ, err := pgx.Connect(context.Background(), pqDB)
146-
if err != nil {
146+
if err != nil {
147147
fmt.Fprintf(os.Stderr, "Unable to connect to database: %v\n", err)
148148
os.Exit(1)
149-
}
149+
}
150150

151151
archivalPQ := postgresql.New(connPQ)
152152

153-
/*
154-
initializing schedular
153+
/*
154+
initializing schedular
155155
scheduler uses context to quit - part of waitgroup
156156
propogates error through error channel
157157
*/
@@ -205,7 +205,7 @@ func run(ctx context.Context) error {
205205
case <-ctx.Done():
206206
zap.L().Info("Shutdown process initiated")
207207
case err = <-errCh:
208-
208+
209209
/* context done can be called here (optional for now) */
210210

211211
zap.L().Error("Fatal Error from schedular",
@@ -239,14 +239,21 @@ func run(ctx context.Context) error {
239239
for _, username := range usernames {
240240
sessionManager.ExpireSession(username)
241241
zap.L().Info("Session forced expired for: ",
242-
zap.String("username", username),
242+
zap.String("username", username),
243243
)
244244
}
245245

246246
wg.Wait()
247247

248+
/* flush Redis data before closing */
249+
if err := logRedisClient.FlushAll(context.Background()); err != nil {
250+
zap.L().Error("Failed to flush Redis data during shutdown",
251+
zap.Error(err),
252+
)
253+
}
254+
248255
/* close archival database connection */
249-
connPQ.Close(context.Background())
256+
connPQ.Close(context.Background())
250257

251258
zap.L().Info("All background processes closed gracefully")
252259

0 commit comments

Comments
 (0)