From 6e5e6ab9fb40aec00e08aead555d8b9f99902110 Mon Sep 17 00:00:00 2001 From: Olof Salberger Date: Mon, 27 May 2024 23:16:07 +0200 Subject: [PATCH] Add description field to jobs --- configparser.go | 1 + crontab.toml | 1 + pgxjob.go | 1 + templates/listjobs.html | 1 + webserver.go | 16 +++++++++------- 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/configparser.go b/configparser.go index 5a038ef..613a2b4 100644 --- a/configparser.go +++ b/configparser.go @@ -46,6 +46,7 @@ func DecodeDatabases(crontab io.Reader, usepgpass bool) (map[string]string, erro type JobMiscOptions struct { SkipValidation bool AllowConcurrentJobs bool + Description string } type JobConfig struct { diff --git a/crontab.toml b/crontab.toml index eb73787..17b8aba 100644 --- a/crontab.toml +++ b/crontab.toml @@ -10,6 +10,7 @@ query="analyze" [test-healthcheck] cronschedule="* * * * *" +description="This is a special healthcheck!" database="test" query="select 1" diff --git a/pgxjob.go b/pgxjob.go index 43890f6..941a6bb 100644 --- a/pgxjob.go +++ b/pgxjob.go @@ -54,6 +54,7 @@ func CreateJob(jobname, dbname string, s Schedule, target, query string, misc Jo Schedule: s, Query: query, config: config, + misc: misc, monitor: monitor, valid: true, }, nil diff --git a/templates/listjobs.html b/templates/listjobs.html index e76ab53..52a2616 100644 --- a/templates/listjobs.html +++ b/templates/listjobs.html @@ -1,6 +1,7 @@ {{ define "jobdisplay" }}

{{ .Icon }} {{ .Name }}

{{if .IsRunning}} {{end}}

Will next run {{ .Nextrun }}

+ {{- if .Description}}

{{.Description}}

{{- end}}

Database:

{{ .Database }}

Query:

{{ .Query }}
Recent runs
diff --git a/webserver.go b/webserver.go index 540daec..53f1c8a 100644 --- a/webserver.go +++ b/webserver.go @@ -31,6 +31,7 @@ type JobDisplay struct { Database string Name string Query string + Description string Icon string IsRunning bool Nextrun time.Time @@ -55,13 +56,14 @@ func computeJobDisplay(ctx context.Context, m Monitor, now time.Time, job Job) ( return display, err } display = JobDisplay{ - Database: job.DbName, - Name: job.JobName, - Query: job.Query, - IsRunning: jobcount != 0, - Icon: "🔵", - Nextrun: job.Schedule.Next(now), - Runs: recent, + Database: job.DbName, + Name: job.JobName, + Query: job.Query, + Description: job.misc.Description, + IsRunning: jobcount != 0, + Icon: "🔵", + Nextrun: job.Schedule.Next(now), + Runs: recent, } if len(recent) > 0 && recent[0].Status == "failed" { display.Icon = "🔴"