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)
|
wg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
persist.PeriodicIntegrityCheck(mainCtx, mainCtxCancel)
|
persist.PeriodicIntegrityCheck(mainCtx,
|
||||||
|
configService.Get().DBIntegrityCheck,
|
||||||
|
mainCtxCancel)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// Start the web server.
|
// Start the web server.
|
||||||
|
@ -73,7 +73,10 @@ type Base struct {
|
|||||||
Meta ConfMeta `yaml:"_meta"`
|
Meta ConfMeta `yaml:"_meta"`
|
||||||
|
|
||||||
ManagerName string `yaml:"manager_name"`
|
ManagerName string `yaml:"manager_name"`
|
||||||
|
|
||||||
DatabaseDSN string `yaml:"database"`
|
DatabaseDSN string `yaml:"database"`
|
||||||
|
DBIntegrityCheck time.Duration `yaml:"database_check_period"`
|
||||||
|
|
||||||
Listen string `yaml:"listen"`
|
Listen string `yaml:"listen"`
|
||||||
|
|
||||||
SSDPDiscovery bool `yaml:"autodiscoverable"`
|
SSDPDiscovery bool `yaml:"autodiscoverable"`
|
||||||
|
@ -20,6 +20,7 @@ var defaultConfig = Conf{
|
|||||||
Listen: ":8080",
|
Listen: ":8080",
|
||||||
// ListenHTTPS: ":8433",
|
// ListenHTTPS: ":8433",
|
||||||
DatabaseDSN: "flamenco-manager.sqlite",
|
DatabaseDSN: "flamenco-manager.sqlite",
|
||||||
|
DBIntegrityCheck: 1 * time.Hour,
|
||||||
SSDPDiscovery: true,
|
SSDPDiscovery: true,
|
||||||
LocalManagerStoragePath: "./flamenco-manager-storage",
|
LocalManagerStoragePath: "./flamenco-manager-storage",
|
||||||
SharedStoragePath: "", // Empty string means "first run", and should trigger the config setup assistant.
|
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 (
|
const (
|
||||||
integrityCheckTimeout = 2 * time.Second
|
integrityCheckTimeout = 2 * time.Second
|
||||||
integrityCheckPeriod = 1 * time.Hour
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type PragmaIntegrityCheckResult struct {
|
type PragmaIntegrityCheckResult struct {
|
||||||
@ -30,15 +29,26 @@ type PragmaForeignKeyCheckResult struct {
|
|||||||
|
|
||||||
// PeriodicIntegrityCheck periodically checks the database integrity.
|
// PeriodicIntegrityCheck periodically checks the database integrity.
|
||||||
// This function only returns when the context is done.
|
// This function only returns when the context is done.
|
||||||
func (db *DB) PeriodicIntegrityCheck(ctx context.Context, onErrorCallback func()) {
|
func (db *DB) PeriodicIntegrityCheck(
|
||||||
log.Debug().Msg("database: periodic integrity check loop starting")
|
ctx context.Context,
|
||||||
defer log.Debug().Msg("database: periodic integrity check loop stopping")
|
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 {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return
|
return
|
||||||
case <-time.After(integrityCheckPeriod):
|
case <-time.After(period):
|
||||||
}
|
}
|
||||||
|
|
||||||
ok := db.performIntegrityCheck(ctx)
|
ok := db.performIntegrityCheck(ctx)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user