fix: stop store-bound workers and reconcile settled repair fixtures
This commit is contained in:
@@ -24,6 +24,8 @@ type Store struct {
|
||||
mu sync.Mutex
|
||||
runnerLock *os.File
|
||||
runnerClaimed bool
|
||||
done chan struct{}
|
||||
closeOnce sync.Once
|
||||
}
|
||||
|
||||
// openDB opens one SQLite connection pool for a DSN. Every open path shares it
|
||||
@@ -51,7 +53,7 @@ CREATE TABLE IF NOT EXISTS submissions (id INTEGER PRIMARY KEY, name TEXT NOT NU
|
||||
db.Close()
|
||||
return nil, err
|
||||
}
|
||||
s := &Store{db: db, dir: filepath.Dir(path), path: path}
|
||||
s := &Store{db: db, dir: filepath.Dir(path), path: path, done: make(chan struct{})}
|
||||
if err := s.initRuns(); err != nil {
|
||||
db.Close()
|
||||
return nil, err
|
||||
@@ -76,6 +78,11 @@ CREATE TABLE IF NOT EXISTS submissions (id INTEGER PRIMARY KEY, name TEXT NOT NU
|
||||
}
|
||||
|
||||
func (s *Store) Close() error {
|
||||
s.closeOnce.Do(func() {
|
||||
if s.done != nil {
|
||||
close(s.done)
|
||||
}
|
||||
})
|
||||
err := s.db.Close()
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
@@ -86,6 +93,11 @@ func (s *Store) Close() error {
|
||||
return err
|
||||
}
|
||||
|
||||
// Done lets runtime workers stop when an embedded caller closes its store even
|
||||
// if the caller supplied a background context. It is not a shutdown substitute
|
||||
// for active execution: callers must still cancel and drain runs before Close.
|
||||
func (s *Store) Done() <-chan struct{} { return s.done }
|
||||
|
||||
// OpenReadOnly opens an existing database without running schema DDL or
|
||||
// changing journal mode, so a live database can be queried read-only while its
|
||||
// server keeps writing. It fails when the file does not exist. It is used by
|
||||
|
||||
Reference in New Issue
Block a user