aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArthur Zamarin <arthurzam@gentoo.org>2024-03-21 20:15:21 +0200
committerArthur Zamarin <arthurzam@gentoo.org>2024-03-21 20:15:21 +0200
commitc7146ea733093e54851ff75b189abb57def0686d (patch)
treee30696a2d008fe960a6b99309cf443115b40c4ce
parentapp/maintainer: add search for packages list (diff)
downloadsoko-c7146ea733093e54851ff75b189abb57def0686d.tar.gz
soko-c7146ea733093e54851ff75b189abb57def0686d.tar.bz2
soko-c7146ea733093e54851ff75b189abb57def0686d.zip
db connection: use better dial timeout instead of just sleep
Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
-rw-r--r--pkg/database/connection.go12
-rw-r--r--soko.go8
2 files changed, 6 insertions, 14 deletions
diff --git a/pkg/database/connection.go b/pkg/database/connection.go
index 53247fe..e698622 100644
--- a/pkg/database/connection.go
+++ b/pkg/database/connection.go
@@ -88,18 +88,18 @@ func (d dbLogger) AfterQuery(c context.Context, q *pg.QueryEvent) error {
// and turn on logging if desired
func Connect() {
DBCon = pg.Connect(&pg.Options{
- User: config.PostgresUser(),
- Password: config.PostgresPass(),
- Database: config.PostgresDb(),
- Addr: config.PostgresHost() + ":" + config.PostgresPort(),
+ User: config.PostgresUser(),
+ Password: config.PostgresPass(),
+ Database: config.PostgresDb(),
+ Addr: config.PostgresHost() + ":" + config.PostgresPort(),
+ DialTimeout: 10 * time.Second,
})
if !config.Quiet() {
DBCon.AddQueryHook(dbLogger{})
}
- err := CreateSchema()
- if err != nil {
+ if err := CreateSchema(); err != nil {
slog.Error("Failed creating database schema", slog.Any("err", err))
os.Exit(1)
}
diff --git a/soko.go b/soko.go
index 34bab62..c38f660 100644
--- a/soko.go
+++ b/soko.go
@@ -27,8 +27,6 @@ import (
func main() {
initLoggers()
- waitForPostgres()
-
serve := flag.Bool("serve", false, "Start serving the application")
selfchecks := flag.Bool("enable-selfchecks", false, "Perform selfchecks periodicals to monitor the consistency of the data")
update := flag.Bool("update", false, "Perform an incremental update of the package data")
@@ -134,12 +132,6 @@ func initLoggers() {
slog.SetDefault(slog.New(handler))
}
-// TODO this has to be solved differently
-// wait for postgres to come up
-func waitForPostgres() {
- time.Sleep(5 * time.Second)
-}
-
func runSelfChecks() {
gocron.Every(1).Hour().From(gocron.NextTick()).Do(selfcheck.AllPackages)
<-gocron.Start()