Skip to content
This repository was archived by the owner on Sep 2, 2024. It is now read-only.

Commit faa6b7f

Browse files
committed
ensure search index file is config and shuts down gracefully
1 parent c803198 commit faa6b7f

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

backend/backend.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,10 @@ func Setup(cfg config.AppConfig) {
228228
}
229229

230230
if !cfg.NoFullTextSearch {
231-
ftsFilename := "sb.fts"
231+
ftsFilename := cfg.FullTextIndexFile
232+
if len(ftsFilename) == 0 {
233+
ftsFilename = "sb.fts"
234+
}
232235
src, err := search.New(ftsFilename, Cache)
233236
if err != nil {
234237
Log.Fatal().Err(err).Msg("unable to start full-text search")

config/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ type AppConfig struct {
8484
LogFilename string
8585
// NoFullTextSearch prevents full-text search index from initializing
8686
NoFullTextSearch bool
87+
// FullTextIndexFile fully qualify file path for the search index
88+
// Hint: this is usually on a disk that do not vanish on each deployment.
89+
FullTextIndexFile string
8790
// ActivateFlag when set, the /account/init can bypass Stripe if matching val
8891
ActivateFlag string
8992
}
@@ -122,6 +125,7 @@ func LoadConfig() AppConfig {
122125
KeepPermissionInName: os.Getenv("KEEP_PERM_COL_NAME") == "",
123126
LogConsoleLevel: os.Getenv("LOG_CONSOLE_LEVEL"),
124127
LogFilename: os.Getenv("LOG_FILENAME"),
128+
FullTextIndexFile: os.Getenv("FTS_INDEX_FILE"),
125129
ActivateFlag: os.Getenv("ACTIVATE_FLAG"),
126130
}
127131
}

search/search.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,9 @@ func (s *Search) receivedIndexEvent(data string) {
185185
log.Println(err)
186186
}
187187
}
188+
189+
func (s *Search) Close() {
190+
if err := s.index.Close(); err != nil {
191+
log.Println(err)
192+
}
193+
}

server.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,9 @@ func Start(c config.AppConfig, log *logger.Logger) {
282282
})
283283
g.Go(func() error {
284284
<-gCtx.Done()
285+
if !c.NoFullTextSearch {
286+
backend.Search.Close()
287+
}
285288
return httpsvr.Shutdown(context.Background())
286289
})
287290

0 commit comments

Comments
 (0)