Manager: make periodic database integrity check configurable
Instead of always performing the periodic integrity check, make it possible to disable it or run it at different intervals. Currently for the Blender Studio it's crunch time, so the check should really only run when there is someone looking at the system (i.e. at restarts for upgrade purposes).
This commit is contained in:
parent
1a79c19583
commit
63634361ce
@ -195,7 +195,9 @@ func runFlamencoManager() bool {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
persist.PeriodicIntegrityCheck(mainCtx, mainCtxCancel)
|
||||
persist.PeriodicIntegrityCheck(mainCtx,
|
||||
configService.Get().DBIntegrityCheck,
|
||||
mainCtxCancel)
|
||||
}()
|
||||
|
||||
// Start the web server.
|
||||
|
@ -73,8 +73,11 @@ type Base struct {
|
||||
Meta ConfMeta `yaml:"_meta"`
|
||||
|
||||
ManagerName string `yaml:"manager_name"`
|
||||
DatabaseDSN string `yaml:"database"`
|
||||
Listen string `yaml:"listen"`
|
||||
|
||||
DatabaseDSN string `yaml:"database"`
|
||||
DBIntegrityCheck time.Duration `yaml:"database_check_period"`
|
||||
|
||||
Listen string `yaml:"listen"`
|
||||
|
||||
SSDPDiscovery bool `yaml:"autodiscoverable"`
|
||||
|
||||
|
@ -20,6 +20,7 @@ var defaultConfig = Conf{
|
||||
Listen: ":8080",
|
||||
// ListenHTTPS: ":8433",
|
||||
DatabaseDSN: "flamenco-manager.sqlite",
|
||||
DBIntegrityCheck: 1 * time.Hour,
|
||||
SSDPDiscovery: true,
|
||||
LocalManagerStoragePath: "./flamenco-manager-storage",
|
||||
SharedStoragePath: "", // Empty string means "first run", and should trigger the config setup assistant.
|
||||
|
@ -14,7 +14,6 @@ var ErrIntegrity = errors.New("database integrity check failed")
|
||||
|
||||
const (
|
||||
integrityCheckTimeout = 2 * time.Second
|
||||
integrityCheckPeriod = 1 * time.Hour
|
||||
)
|
||||
|
||||
type PragmaIntegrityCheckResult struct {
|
||||
@ -30,15 +29,26 @@ type PragmaForeignKeyCheckResult struct {
|
||||
|
||||
// PeriodicIntegrityCheck periodically checks the database integrity.
|
||||
// This function only returns when the context is done.
|
||||
func (db *DB) PeriodicIntegrityCheck(ctx context.Context, onErrorCallback func()) {
|
||||
log.Debug().Msg("database: periodic integrity check loop starting")
|
||||
defer log.Debug().Msg("database: periodic integrity check loop stopping")
|
||||
func (db *DB) PeriodicIntegrityCheck(
|
||||
ctx context.Context,
|
||||
period time.Duration,
|
||||
onErrorCallback func(),
|
||||
) {
|
||||
if period == 0 {
|
||||
log.Info().Msg("database: periodic integrity check disabled")
|
||||
return
|
||||
}
|
||||
|
||||
log.Info().
|
||||
Stringer("period", period).
|
||||
Msg("database: periodic integrity check starting")
|
||||
defer log.Debug().Msg("database: periodic integrity check stopping")
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case <-time.After(integrityCheckPeriod):
|
||||
case <-time.After(period):
|
||||
}
|
||||
|
||||
ok := db.performIntegrityCheck(ctx)
|
||||
|
Loading…
x
Reference in New Issue
Block a user