Skip to content

Commit

Permalink
Merge pull request #2 from xzclinux/master
Browse files Browse the repository at this point in the history
Fixed an issue where metrics were not updated when the database was down
  • Loading branch information
NoahAmethyst authored Nov 15, 2023
2 parents 6e2146c + dee43a3 commit bb2fac2
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions job.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@ func (j *Job) runOnce() error {
func (c *connection) connect(job *Job) error {
// already connected
if c.conn != nil {
err := c.conn.Ping()
if err != nil {
job.clearmetrics()
}
return nil
}
dsn := c.url
Expand Down Expand Up @@ -279,3 +283,17 @@ func (c *connection) connect(job *Job) error {
c.conn = conn
return nil
}

func (j *Job) clearmetrics() {
for qi, query := range j.Queries {
if query == nil {
continue
}
for mi, metrics := range query.metrics {
if metrics != nil {
j.Queries[qi].metrics[mi] = nil
}
}

}
}

0 comments on commit bb2fac2

Please sign in to comment.