mirror of
https://github.com/GlueOps/autoglue.git
synced 2026-02-13 12:50:05 +01:00
initial jobs dashboard
This commit is contained in:
@@ -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 we’re 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() }
|
||||
|
||||
Reference in New Issue
Block a user