mirror of
https://github.com/status-im/go-waku.git
synced 2025-01-13 15:24:46 +00:00
chore: print a message periodically indicating that VACUUM is still being executed (#838)
This commit is contained in:
parent
db222a24ef
commit
279752344f
@ -1,8 +1,10 @@
|
||||
package postgres
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/golang-migrate/migrate/v4/database"
|
||||
"github.com/golang-migrate/migrate/v4/database/pgx"
|
||||
@ -15,10 +17,35 @@ import (
|
||||
|
||||
func executeVacuum(db *sql.DB, logger *zap.Logger) error {
|
||||
logger.Info("starting PostgreSQL database vacuuming")
|
||||
_, err := db.Exec("VACUUM FULL")
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
errCh := make(chan error)
|
||||
|
||||
go func() {
|
||||
defer cancel()
|
||||
_, err := db.Exec("VACUUM FULL")
|
||||
if err != nil {
|
||||
errCh <- err
|
||||
}
|
||||
}()
|
||||
|
||||
t := time.NewTicker(2 * time.Minute)
|
||||
defer t.Stop()
|
||||
|
||||
loop:
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
break loop
|
||||
case err := <-errCh:
|
||||
return err
|
||||
case <-t.C:
|
||||
logger.Info("still vacuuming...")
|
||||
}
|
||||
}
|
||||
|
||||
logger.Info("finished PostgreSQL database vacuuming")
|
||||
return nil
|
||||
}
|
||||
|
@ -1,9 +1,11 @@
|
||||
package sqlite
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/golang-migrate/migrate/v4/database"
|
||||
"github.com/golang-migrate/migrate/v4/database/sqlite3"
|
||||
@ -32,10 +34,35 @@ func addSqliteURLDefaults(dburl string) string {
|
||||
|
||||
func executeVacuum(db *sql.DB, logger *zap.Logger) error {
|
||||
logger.Info("starting sqlite database vacuuming")
|
||||
_, err := db.Exec("VACUUM")
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
errCh := make(chan error)
|
||||
|
||||
go func() {
|
||||
defer cancel()
|
||||
_, err := db.Exec("VACUUM")
|
||||
if err != nil {
|
||||
errCh <- err
|
||||
}
|
||||
}()
|
||||
|
||||
t := time.NewTicker(2 * time.Minute)
|
||||
defer t.Stop()
|
||||
|
||||
loop:
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
break loop
|
||||
case err := <-errCh:
|
||||
return err
|
||||
case <-t.C:
|
||||
logger.Info("still vacuuming...")
|
||||
}
|
||||
}
|
||||
|
||||
logger.Info("finished sqlite database vacuuming")
|
||||
return nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user