Skip to content

Commit 06a3106

Browse files
committed
chore: register and update the node before starting the node
1 parent 9f162be commit 06a3106

File tree

4 files changed

+26
-22
lines changed

4 files changed

+26
-22
lines changed

cmd/start.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package cmd
22

33
import (
4+
"context"
45
"fmt"
56
"os/signal"
67
"syscall"
78

89
"github.com/sentinel-official/sentinel-go-sdk/libs/log"
10+
"github.com/sentinel-official/sentinel-go-sdk/utils"
911
"github.com/spf13/cobra"
1012
"github.com/spf13/viper"
1113
"golang.org/x/sync/errgroup"
@@ -69,6 +71,14 @@ explicitly starts the node, and handles SIGINT/SIGTERM for graceful shutdown.`,
6971

7072
// Launch goroutine to start the node and wait.
7173
eg.Go(func() error {
74+
// Register the node and update its details.
75+
if err := n.Register(ctx); err != nil {
76+
return fmt.Errorf("registering node: %w", err)
77+
}
78+
if err := n.UpdateDetails(ctx); err != nil {
79+
return fmt.Errorf("updating node details: %w", err)
80+
}
81+
7282
log.Info("Starting node")
7383
if err := n.Start(); err != nil {
7484
return fmt.Errorf("starting node: %w", err)
@@ -83,20 +93,14 @@ explicitly starts the node, and handles SIGINT/SIGTERM for graceful shutdown.`,
8393
return nil
8494
})
8595

86-
// Register the node and update its details.
87-
if err := n.Register(ctx); err != nil {
88-
return fmt.Errorf("registering node: %w", err)
89-
}
90-
if err := n.UpdateDetails(ctx); err != nil {
91-
return fmt.Errorf("updating node details: %w", err)
92-
}
93-
9496
return nil
9597
})
9698

9799
// Wait for all goroutines to complete.
98100
if err := eg.Wait(); err != nil {
99-
return err
101+
if !utils.ErrorIs(err, context.Canceled) {
102+
return err
103+
}
100104
}
101105

102106
log.Info("Node stopped successfully")

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ require (
77
github.com/cosmos/cosmos-sdk v0.47.17
88
github.com/gin-contrib/cors v1.7.6
99
github.com/gin-gonic/gin v1.10.1
10-
github.com/sentinel-official/sentinel-go-sdk v1.0.0-rc.6.0.20250826104258-944c68bd5d29
10+
github.com/sentinel-official/sentinel-go-sdk v1.0.0-rc.6.0.20250826115632-ff01e4ef3e44
1111
github.com/sentinel-official/sentinelhub/v12 v12.0.0-rc.11
1212
github.com/spf13/cobra v1.9.1
1313
github.com/spf13/pflag v1.0.7

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -511,8 +511,8 @@ github.com/secure-io/siv-go v0.0.0-20180922214919-5ff40651e2c4 h1:zOjq+1/uLzn/Xo
511511
github.com/secure-io/siv-go v0.0.0-20180922214919-5ff40651e2c4/go.mod h1:aI+8yClBW+1uovkHw6HM01YXnYB8vohtB9C83wzx34E=
512512
github.com/seiflotfy/cuckoofilter v0.0.0-20220411075957-e3b120b3f5fb h1:XfLJSPIOUX+osiMraVgIrMR27uMXnRJWGm1+GL8/63U=
513513
github.com/seiflotfy/cuckoofilter v0.0.0-20220411075957-e3b120b3f5fb/go.mod h1:bR6DqgcAl1zTcOX8/pE2Qkj9XO00eCNqmKb7lXP8EAg=
514-
github.com/sentinel-official/sentinel-go-sdk v1.0.0-rc.6.0.20250826104258-944c68bd5d29 h1:NJZLzxhNl1IJ9YoU2y92WFDNVYP6MmaYRNp0NCj+MuI=
515-
github.com/sentinel-official/sentinel-go-sdk v1.0.0-rc.6.0.20250826104258-944c68bd5d29/go.mod h1:jatyUZIc/7I7xmLI6fmbhzMjJ+si04XR2f0CksWtiXw=
514+
github.com/sentinel-official/sentinel-go-sdk v1.0.0-rc.6.0.20250826115632-ff01e4ef3e44 h1:zXo3qyKpKX4klGnhiDcfSGt0QU+cQQB2txgqM8EF2zs=
515+
github.com/sentinel-official/sentinel-go-sdk v1.0.0-rc.6.0.20250826115632-ff01e4ef3e44/go.mod h1:jatyUZIc/7I7xmLI6fmbhzMjJ+si04XR2f0CksWtiXw=
516516
github.com/sentinel-official/sentinelhub/v12 v12.0.0-rc.11 h1:B3ylnKZSLP9aDYnS2f98Gx/QTohPuD36tjl75kYJSMs=
517517
github.com/sentinel-official/sentinelhub/v12 v12.0.0-rc.11/go.mod h1:LXcOAEffAn4Pw58xhoYN9j8ZVuM02OCgPNTI6lkGG2E=
518518
github.com/shirou/gopsutil/v4 v4.25.7 h1:bNb2JuqKuAu3tRlPv5piSmBZyMfecwQ+t/ILq+1JqVM=

node/node.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,10 @@ func (n *Node) UpdateDetails(ctx context.Context) error {
115115

116116
// Start initializes the Node's services, scheduler, and API server.
117117
func (n *Node) Start() error {
118-
eg := &errgroup.Group{}
118+
sg := &errgroup.Group{}
119119

120120
// Launch the service stack as a background goroutine.
121-
eg.Go(func() error {
121+
sg.Go(func() error {
122122
log.Info("Running service pre-up task")
123123
if err := n.Service().PreUp(); err != nil {
124124
return fmt.Errorf("running service pre-up task: %w", err)
@@ -146,7 +146,7 @@ func (n *Node) Start() error {
146146
})
147147

148148
// Launch the cron-based job scheduler in the background.
149-
eg.Go(func() error {
149+
sg.Go(func() error {
150150
log.Info("Starting scheduler")
151151
if err := n.Scheduler().Start(); err != nil {
152152
return fmt.Errorf("starting scheduler: %w", err)
@@ -164,7 +164,7 @@ func (n *Node) Start() error {
164164
})
165165

166166
// Launch the API server using the configured TLS certificates and router.
167-
eg.Go(func() error {
167+
sg.Go(func() error {
168168
log.Info("Starting API server", "addr", n.APIListenAddr())
169169
if err := n.Server().Start(); err != nil {
170170
return fmt.Errorf("starting API server: %w", err)
@@ -182,7 +182,7 @@ func (n *Node) Start() error {
182182
})
183183

184184
// Wait until all routines started
185-
if err := eg.Wait(); err != nil {
185+
if err := sg.Wait(); err != nil {
186186
return err
187187
}
188188

@@ -200,9 +200,9 @@ func (n *Node) Wait() error {
200200

201201
// Stop gracefully stops the Node's operations.
202202
func (n *Node) Stop() error {
203-
eg := &errgroup.Group{}
203+
sg := &errgroup.Group{}
204204

205-
eg.Go(func() error {
205+
sg.Go(func() error {
206206
log.Info("Running service pre-down task")
207207
if err := n.Service().PreDown(); err != nil {
208208
return fmt.Errorf("running service pre-down task: %w", err)
@@ -221,7 +221,7 @@ func (n *Node) Stop() error {
221221
return nil
222222
})
223223

224-
eg.Go(func() error {
224+
sg.Go(func() error {
225225
log.Info("Stopping scheduler")
226226
if err := n.Scheduler().Stop(); err != nil {
227227
return fmt.Errorf("stopping scheduler: %w", err)
@@ -230,7 +230,7 @@ func (n *Node) Stop() error {
230230
return nil
231231
})
232232

233-
eg.Go(func() error {
233+
sg.Go(func() error {
234234
log.Info("Stopping API server")
235235
if err := n.Server().Stop(); err != nil {
236236
return fmt.Errorf("stopping API server: %w", err)
@@ -239,7 +239,7 @@ func (n *Node) Stop() error {
239239
return nil
240240
})
241241

242-
if err := eg.Wait(); err != nil {
242+
if err := sg.Wait(); err != nil {
243243
return err
244244
}
245245

0 commit comments

Comments
 (0)