mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-26 05:17:22 +00:00
a468a12ef0
* move flags * backup db output dir flag * fix build * fix up broken backup test * Radek's feedback Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
30 lines
737 B
Go
30 lines
737 B
Go
package db
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
// BackupHandler for accepting requests to initiate a new database backup.
|
|
func BackupHandler(db Database, outputDir string) func(http.ResponseWriter, *http.Request) {
|
|
log := logrus.WithField("prefix", "db")
|
|
|
|
return func(w http.ResponseWriter, _ *http.Request) {
|
|
log.Debug("Creating database backup from HTTP webhook.")
|
|
|
|
if err := db.Backup(context.Background(), outputDir); err != nil {
|
|
log.WithError(err).Error("Failed to create backup")
|
|
w.WriteHeader(http.StatusInternalServerError)
|
|
return
|
|
}
|
|
w.WriteHeader(http.StatusOK)
|
|
_, err := fmt.Fprint(w, "OK")
|
|
if err != nil {
|
|
log.WithError(err).Error("Failed to write OK")
|
|
}
|
|
}
|
|
}
|