mirror of
https://github.com/status-im/go-waku.git
synced 2025-01-27 22:15:38 +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
|
package postgres
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/golang-migrate/migrate/v4/database"
|
"github.com/golang-migrate/migrate/v4/database"
|
||||||
"github.com/golang-migrate/migrate/v4/database/pgx"
|
"github.com/golang-migrate/migrate/v4/database/pgx"
|
||||||
@ -15,10 +17,35 @@ import (
|
|||||||
|
|
||||||
func executeVacuum(db *sql.DB, logger *zap.Logger) error {
|
func executeVacuum(db *sql.DB, logger *zap.Logger) error {
|
||||||
logger.Info("starting PostgreSQL database vacuuming")
|
logger.Info("starting PostgreSQL database vacuuming")
|
||||||
_, err := db.Exec("VACUUM FULL")
|
|
||||||
if err != nil {
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
return err
|
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")
|
logger.Info("finished PostgreSQL database vacuuming")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
package sqlite
|
package sqlite
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/golang-migrate/migrate/v4/database"
|
"github.com/golang-migrate/migrate/v4/database"
|
||||||
"github.com/golang-migrate/migrate/v4/database/sqlite3"
|
"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 {
|
func executeVacuum(db *sql.DB, logger *zap.Logger) error {
|
||||||
logger.Info("starting sqlite database vacuuming")
|
logger.Info("starting sqlite database vacuuming")
|
||||||
_, err := db.Exec("VACUUM")
|
|
||||||
if err != nil {
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
return err
|
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")
|
logger.Info("finished sqlite database vacuuming")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user