Skip to content

Commit ecf95d6

Browse files
authored
feat(flagd): add Shutdown support for in-process sync (#687)
Signed-off-by: liran2000 <[email protected]>
1 parent b435fb4 commit ecf95d6

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

providers/flagd/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ In the above example, in-process handlers attempt to connect to a sync service o
4343
#### Custom sync provider
4444

4545
In-process resolver can also be configured with a custom sync provider to change how the in-process resolver fetches flags.
46-
The custom sync provider must implement the [sync.ISync interface](https://github.com/open-feature/flagd/blob/main/core/pkg/sync/isync.go). Optional URI can be provided for the custom sync provider.
46+
The custom sync provider must implement the [sync.ISync interface](https://github.com/open-feature/flagd/blob/main/core/pkg/sync/isync.go). Optional URI can be provided for the custom sync provider.
47+
The custom sync provider can implement the _sync.Shutdowner_ interface from [service](https://github.com/open-feature/go-sdk-contrib/blob/main/providers/flagd/pkg/service/in_process/service.go).
4748

4849
```go
4950
var syncProvider sync.ISync = MyAwesomeSyncProvider{}

providers/flagd/pkg/service/in_process/service.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"regexp"
88
parallel "sync"
99

10+
"go.uber.org/zap"
1011
googlegrpc "google.golang.org/grpc"
1112

1213
"github.com/open-feature/flagd/core/pkg/evaluator"
@@ -46,6 +47,10 @@ type Configuration struct {
4647
GrpcDialOptionsOverride []googlegrpc.DialOption
4748
}
4849

50+
type Shutdowner interface {
51+
Shutdown() error
52+
}
53+
4954
func NewInProcessService(cfg Configuration) *InProcess {
5055
log := logger.NewLogger(NewRaw(), false)
5156

@@ -116,6 +121,12 @@ func (i *InProcess) Init() error {
116121
ProviderEventDetails: of.ProviderEventDetails{Message: "New flag sync", FlagChanges: maps.Keys(changes)}}
117122
case <-i.listenerShutdown:
118123
i.logger.Info("Shutting down data sync listener")
124+
if shutdowner, ok := i.sync.(Shutdowner); ok {
125+
err := shutdowner.Shutdown()
126+
if err != nil {
127+
i.logger.Error("Error shutdown sync provider", zap.Error(err))
128+
}
129+
}
119130
return
120131
}
121132
}

0 commit comments

Comments
 (0)