Skip to content

Commit

Permalink
Substreams app(s) gained ability to check if shutdown is pending
Browse files Browse the repository at this point in the history
  • Loading branch information
maoueh committed Jan 19, 2024
1 parent 9197246 commit 7de579a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
7 changes: 6 additions & 1 deletion app/tier1.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type Tier1Modules struct {
Authenticator dauth.Authenticator
HeadTimeDriftMetric *dmetrics.HeadTimeDrift
HeadBlockNumberMetric *dmetrics.HeadBlockNum
CheckPendingShutDown func() bool
}

type Tier1Config struct {
Expand Down Expand Up @@ -191,7 +192,7 @@ func (a *Tier1App) Run() error {
}

a.logger.Info("launching gRPC server", zap.Bool("live_support", withLive))
a.isReady.CAS(false, true)
a.isReady.CompareAndSwap(false, true)

err := service.ListenTier1(a.config.GRPCListenAddr, svc, a.modules.Authenticator, a.logger, a.HealthCheck)
a.Shutdown(err)
Expand All @@ -214,6 +215,10 @@ func (a *Tier1App) IsReady(ctx context.Context) bool {
return false
}

if a.modules.CheckPendingShutDown != nil && a.modules.CheckPendingShutDown() {
return false
}

return a.isReady.Load()
}

Expand Down
14 changes: 12 additions & 2 deletions app/tier2.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,20 @@ type Tier2Config struct {
type Tier2App struct {
*shutter.Shutter
config *Tier2Config
modules *Tier2Modules
logger *zap.Logger
isReady *atomic.Bool
}

func NewTier2(logger *zap.Logger, config *Tier2Config) *Tier2App {
type Tier2Modules struct {
CheckPendingShutDown func() bool
}

func NewTier2(logger *zap.Logger, config *Tier2Config, modules *Tier2Modules) *Tier2App {
return &Tier2App{
Shutter: shutter.New(),
config: config,
modules: modules,
logger: logger,

isReady: atomic.NewBool(false),
Expand Down Expand Up @@ -100,7 +106,7 @@ func (a *Tier2App) Run() error {

go func() {
a.logger.Info("launching gRPC server")
a.isReady.CAS(false, true)
a.isReady.CompareAndSwap(false, true)

err := service.ListenTier2(a.config.GRPCListenAddr, a.config.ServiceDiscoveryURL, svc, trustAuth, a.logger, a.HealthCheck)
a.Shutdown(err)
Expand All @@ -120,6 +126,10 @@ func (a *Tier2App) IsReady(ctx context.Context) bool {
return false
}

if a.modules.CheckPendingShutDown != nil && a.modules.CheckPendingShutDown() {
return false
}

return a.isReady.Load()
}

Expand Down

0 comments on commit 7de579a

Please sign in to comment.