Skip to content

Commit 29c238d

Browse files
committed
chore: improved logs
1 parent eb598f5 commit 29c238d

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

cmd/start.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ explicitly starts the node, and handles SIGINT/SIGTERM for graceful shutdown.`,
6464
eg.Go(func() error {
6565
// Wait until signal is received
6666
<-ctx.Done()
67+
log.Info("Stop signal received, shutting down gracefully")
6768

6869
if err := n.Stop(); err != nil {
6970
log.Error("Failed to stop node", "cause", err)
@@ -89,6 +90,7 @@ explicitly starts the node, and handles SIGINT/SIGTERM for graceful shutdown.`,
8990
return err
9091
}
9192

93+
log.Info("Node stopped successfully")
9294
return nil
9395
},
9496
}

node/node.go

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package node
33
import (
44
"context"
55
"fmt"
6+
"sync"
67

78
"github.com/gin-gonic/gin"
89
"github.com/sentinel-official/sentinel-go-sdk/libs/cmux"
@@ -72,7 +73,12 @@ func (n *Node) Register(ctx context.Context) error {
7273
return nil
7374
}
7475

75-
log.Info("Registering node...")
76+
log.Info("Registering node",
77+
"addr", n.NodeAddr(),
78+
"gigabyte_price", n.GigabytePrices(),
79+
"hourly_price", n.HourlyPrices(),
80+
"remote_addrs", n.APIAddrs(),
81+
)
7682

7783
// Prepare a message to register the node.
7884
msg := v3.NewMsgRegisterNodeRequest(
@@ -92,7 +98,12 @@ func (n *Node) Register(ctx context.Context) error {
9298

9399
// UpdateDetails updates the node's pricing and address details on the network.
94100
func (n *Node) UpdateDetails(ctx context.Context) error {
95-
log.Info("Updating node details...")
101+
log.Info("Updating node details",
102+
"addr", n.NodeAddr(),
103+
"gigabyte_prices", n.GigabytePrices(),
104+
"hourly_prices", n.HourlyPrices(),
105+
"remote_addrs", n.APIAddrs(),
106+
)
96107

97108
// Prepare a message to update the node's details.
98109
msg := v3.NewMsgUpdateNodeDetailsRequest(
@@ -125,8 +136,16 @@ func (n *Node) Start(ctx context.Context) error {
125136
return fmt.Errorf("failed to update node details: %w", err)
126137
}
127138

139+
var start sync.WaitGroup
140+
start.Add(3)
141+
128142
// Launch the service stack as a background goroutine.
129143
n.eg.Go(func() error {
144+
log.Info("Starting service routine", "type", n.Service().Type())
145+
start.Done()
146+
147+
defer log.Info("Exiting service routine")
148+
130149
if err := n.Service().Up(ctx); err != nil {
131150
return fmt.Errorf("failed to run service up task: %w", err)
132151
}
@@ -142,6 +161,11 @@ func (n *Node) Start(ctx context.Context) error {
142161

143162
// Launch the cron-based job scheduler in the background.
144163
n.eg.Go(func() error {
164+
log.Info("Starting scheduler routine")
165+
start.Done()
166+
167+
defer log.Info("Exiting scheduler routine")
168+
145169
if err := n.Scheduler().Start(ctx); err != nil {
146170
return fmt.Errorf("failed to start scheduler: %w", err)
147171
}
@@ -154,13 +178,21 @@ func (n *Node) Start(ctx context.Context) error {
154178

155179
// Launch the API server using the configured TLS certificates and router.
156180
n.eg.Go(func() error {
181+
log.Info("Starting API server routine", "listen", n.APIListenAddr())
182+
start.Done()
183+
184+
defer log.Info("Exiting API server routine")
185+
157186
if err := cmux.ListenAndServeTLS(ctx, n.APIListenAddr(), n.TLSCertFile(), n.TLSKeyFile(), n.Router()); err != nil {
158187
return fmt.Errorf("failed to listen and serve tls: %w", err)
159188
}
160189

161190
return nil
162191
})
163192

193+
// Wait until all routines started
194+
start.Wait()
195+
164196
log.Info("Node started successfully")
165197
return nil
166198
}
@@ -195,6 +227,5 @@ func (n *Node) Stop() error {
195227
return fmt.Errorf("failed to stop scheduler: %w", err)
196228
}
197229

198-
log.Info("Node stopped successfully")
199230
return nil
200231
}

0 commit comments

Comments
 (0)