Skip to content

Commit 768e538

Browse files
committed
Fix integration of Lifecycle and health
1 parent d5418c9 commit 768e538

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# vNext
22

3+
# v1.4.4
4+
5+
- (bug) Fix integration of Lifecycle and health
6+
37
# v1.4.3
48

59
- (improvement) Initialize json implementation on startup

app/lifecycle.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import "context"
55
type LifecycleHook func(ctx context.Context) error
66

77
type Lifecycle struct {
8-
onStart []LifecycleHook
9-
onStop []LifecycleHook
10-
onStopLast []LifecycleHook
8+
onStart []LifecycleHook
9+
onStopFirst []LifecycleHook
10+
onStop []LifecycleHook
11+
onStopLast []LifecycleHook
1112
}
1213

1314
func NewLifecycle() *Lifecycle {
@@ -27,6 +28,12 @@ func (l *Lifecycle) Start(ctx context.Context) error {
2728
func (l *Lifecycle) Stop() error {
2829
ctx := context.Background()
2930

31+
for _, hook := range l.onStopFirst {
32+
if err := hook(ctx); err != nil {
33+
return err
34+
}
35+
}
36+
3037
for _, hook := range l.onStop {
3138
if err := hook(ctx); err != nil {
3239
return err
@@ -50,6 +57,10 @@ func (l *Lifecycle) OnStop(hook LifecycleHook) {
5057
l.onStop = append(l.onStop, hook)
5158
}
5259

60+
func (l *Lifecycle) OnStopFirst(hook LifecycleHook) {
61+
l.onStopFirst = append(l.onStopFirst, hook)
62+
}
63+
5364
func (l *Lifecycle) OnStopLast(hook LifecycleHook) {
5465
l.onStopLast = append(l.onStopLast, hook)
5566
}

health/service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func New(logger golog.Logger, lifecycle *app.Lifecycle) *Service {
2626
logger: logger,
2727
}
2828

29-
lifecycle.OnStop(func(ctx context.Context) error {
29+
lifecycle.OnStopFirst(func(ctx context.Context) error {
3030
s.SetUnhealthy("lifecycle", "Service is shutting down")
3131
return nil
3232
})

0 commit comments

Comments
 (0)