Skip to content

Commit

Permalink
Auto reload route from CS every minute
Browse files Browse the repository at this point in the history
This is a fail safe in-case the listen/notify mechanism.
  • Loading branch information
theseanything committed Nov 25, 2024
1 parent b7fc3c6 commit 0c38590
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/load_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/http"
"net/url"
"strconv"
"time"

"github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgconn"
Expand Down Expand Up @@ -140,6 +141,15 @@ func (rt *Router) listenForContentStoreUpdates(ctx context.Context) error {
return nil
}

func (rt *Router) PeriodicCSRouteUpdates() {
tick := time.Tick(time.Minute)
for range tick {
if time.Since(rt.csLastReloadTime) > time.Minute {
rt.CsReloadChan <- true
}
}
}

func (rt *Router) waitForReload() {
for range rt.CsReloadChan {
func() {
Expand Down
1 change: 1 addition & 0 deletions lib/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type Router struct {
ReloadChan chan bool
CsReloadChan chan bool
csMuxSampleRate float64
csLastReloadTime time.Time
pool *pgxpool.Pool
}

Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ func main() {
if err != nil {
log.Fatal(err)
}
go rout.PeriodicCSRouteUpdates()
go rout.SelfUpdateRoutes()

go listenAndServeOrFatal(pubAddr, rout, feReadTimeout, feWriteTimeout)
Expand Down

0 comments on commit 0c38590

Please sign in to comment.