initial jobs dashboard

This commit is contained in:
allanice001
2025-09-23 05:33:20 +01:00
parent c50fc1540a
commit 4ee03d5409
27 changed files with 2218 additions and 205 deletions

View File

@@ -1,4 +1,3 @@
// internal/bg/bg.go
package bg
import (
@@ -11,10 +10,13 @@ import (
"github.com/dyaksa/archer"
"github.com/spf13/viper"
"gorm.io/gorm"
)
type Jobs struct{ Client *archer.Client }
var BgJobs *Jobs
func archerOptionsFromDSN(dsn string) (*archer.Options, error) {
u, err := url.Parse(dsn)
if err != nil {
@@ -40,7 +42,7 @@ func archerOptionsFromDSN(dsn string) (*archer.Options, error) {
}, nil
}
func NewJobs() (*Jobs, error) {
func NewJobs(gdb *gorm.DB) (*Jobs, error) {
opts, err := archerOptionsFromDSN(viper.GetString("database.dsn"))
if err != nil {
return nil, err
@@ -54,6 +56,10 @@ func NewJobs() (*Jobs, error) {
if timeoutSec <= 0 {
timeoutSec = 60
}
retainDays := viper.GetInt("archer.cleanup_retain_days")
if retainDays <= 0 {
retainDays = 7
}
// LOG what were connecting to (sanitized) so you can confirm DB/host
log.Printf("[archer] addr=%s db=%s user=%s ssl=%s", opts.Addr, opts.DBName, opts.User, opts.SSL)
@@ -74,7 +80,15 @@ func NewJobs() (*Jobs, error) {
archer.WithTimeout(time.Duration(timeoutSec)*time.Second),
)
return &Jobs{Client: c}, nil
jobs := &Jobs{Client: c}
c.Register(
"archer_cleanup",
CleanupWorker(gdb, jobs, retainDays),
archer.WithInstances(1),
archer.WithTimeout(5*time.Minute),
)
return jobs, nil
}
func (j *Jobs) Start() error { return j.Client.Start() }