feat(core-service): satisfy core lifecycle contract
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
afe7b6e9de
commit
06a5fe9ac8
2 changed files with 12 additions and 3 deletions
|
|
@ -21,6 +21,9 @@ type CoreService struct {
|
|||
hookInstalled bool
|
||||
}
|
||||
|
||||
var _ core.Startable = (*CoreService)(nil)
|
||||
var _ core.Stoppable = (*CoreService)(nil)
|
||||
|
||||
func (s *CoreService) wrapped() *Service {
|
||||
if s == nil {
|
||||
return nil
|
||||
|
|
@ -135,11 +138,16 @@ func NewCoreService(opts ServiceOptions) func(*core.Core) (any, error) {
|
|||
}
|
||||
|
||||
// OnStartup initialises the i18n service.
|
||||
func (s *CoreService) OnStartup(_ context.Context) error {
|
||||
func (s *CoreService) OnStartup(_ context.Context) core.Result {
|
||||
if svc := s.wrapped(); svc != nil && svc.Mode() == ModeCollect {
|
||||
s.ensureMissingKeyCollector()
|
||||
}
|
||||
return nil
|
||||
return core.Result{OK: true}
|
||||
}
|
||||
|
||||
// OnShutdown finalises the i18n service.
|
||||
func (s *CoreService) OnShutdown(_ context.Context) core.Result {
|
||||
return core.Result{OK: true}
|
||||
}
|
||||
|
||||
func (s *CoreService) ensureMissingKeyCollector() {
|
||||
|
|
|
|||
|
|
@ -40,7 +40,8 @@ func TestCoreServiceNilSafe(t *testing.T) {
|
|||
})
|
||||
assert.Nil(t, defaultService.Load())
|
||||
|
||||
assert.NoError(t, svc.OnStartup(nil))
|
||||
assert.Equal(t, core.Result{OK: true}, svc.OnStartup(nil))
|
||||
assert.Equal(t, core.Result{OK: true}, svc.OnShutdown(nil))
|
||||
svc.SetMode(ModeCollect)
|
||||
svc.SetFallback("fr")
|
||||
svc.SetFormality(FormalityFormal)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue