feat(conga,dev): worker and scheduler reports, summer dev runs serve

- queue:work and schedule:run print a startup summary and a shutdown
  report on a terminal, log them as records otherwise, and return nil
  after a clean stop
- schedule:run --once ends with 'Ran N due entries (M failed)'
- summer dev runs bin/<app> serve with the forwarded global options,
  reports through Output, stops the old server before starting the new
  one and prints a dev report on Ctrl+C (exit 0)
- lagoon.DatabaseLabel describes a DSN without its secrets
- Long help and examples for queue:work, schedule:run, dev, docs:serve
This commit is contained in:
Jakub Zych
2026-10-21 13:04:27 +02:00
parent c38dc1fe48
commit 168d65cd1b
15 changed files with 319 additions and 81 deletions

View File

@@ -4,12 +4,14 @@ import (
"context"
"database/sql"
"fmt"
"strconv"
"strings"
"time"
"git.golem15.com/golem15/summercms/modules/backpack"
"git.golem15.com/golem15/summercms/modules/compass"
"git.golem15.com/golem15/summercms/modules/diary"
"github.com/jackc/pgx/v5/pgconn"
_ "github.com/jackc/pgx/v5/stdlib"
"gorm.io/driver/postgres"
"gorm.io/gorm"
@@ -122,6 +124,33 @@ func DSN(cfg *compass.Config) string {
return strings.TrimSpace(cfg.String("database.dsn"))
}
// DatabaseLabel describes dsn for a person without its secrets: host:port/name
// parsed with pgconn.ParseConfig (a Unix socket directory reads "socket
// <dir>"), never the user or password. An empty DSN is "not configured", one
// that does not parse "configured". serve and queue:work print it in their
// startup summaries.
func DatabaseLabel(dsn string) string {
dsn = strings.TrimSpace(dsn)
if dsn == "" {
return "not configured"
}
cfg, err := pgconn.ParseConfig(dsn)
if err != nil || cfg.Host == "" {
return "configured"
}
host := cfg.Host
if strings.HasPrefix(host, "/") {
host = "socket " + host
} else if strings.Contains(host, ":") {
host = "[" + host + "]"
}
label := host + ":" + strconv.Itoa(int(cfg.Port))
if cfg.Database != "" {
label += "/" + cfg.Database
}
return label
}
// Publish stores the shared SQL pool and GORM handle on the app. Both
// handles refer to the same *sql.DB. It then runs the callbacks queued by
// OnDatabase and returns the first error.