Skip to content

Commit

Permalink
Rename refresh_interval_seconds to force_refresh_interval_seconds
Browse files Browse the repository at this point in the history
… and use `FullReconnect` for force refreshes
  • Loading branch information
javiercr committed May 15, 2024
1 parent d62b28e commit a984cbd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type Config struct {
Proxy string `yaml:"proxy"`
GetProxyFrom string `yaml:"get_proxy_from"`
MinFullReconnectIntervalSeconds int `yaml:"min_full_reconnect_interval_seconds"`
ForceRefreshIntervalSeconds int `yaml:"force_refresh_interval_seconds"`
} `yaml:"meta"`

Bridge BridgeConfig `yaml:"bridge"`
Expand Down
4 changes: 2 additions & 2 deletions example-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ meta:
# HTTP endpoint to request new proxy address from, for dynamically assigned proxies.
# The endpoint must return a JSON body with a string field called proxy_url.
get_proxy_from:
# Interval to force refresh the connection (disconnect and re-connect), default is 1 day. Set 0 to disable refreshes.
refresh_interval_seconds: 86400
# Minimum interval between full reconnects in seconds
min_full_reconnect_interval_seconds: 1
# Interval to force refresh the connection (full reconnect), default is 1 day. Set 0 to disable refreshes.
force_refresh_interval_seconds: 30

# Bridge config
bridge:
Expand Down
13 changes: 6 additions & 7 deletions user.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,16 +542,15 @@ func (user *User) unlockedConnect() {
go user.sendMarkdownBridgeAlert(context.TODO(), "Failed to connect to %s: %v", user.bridge.ProtocolName, err)
}

var refreshIntervalSeconds = user.bridge.Config.Meta.RefreshIntervalSeconds
user.log.Debug().Uint64("refresh_interval_seconds", refreshIntervalSeconds).Msg("Setting refresh interval")

if refreshIntervalSeconds > 0 {
refreshInterval := time.Duration(user.bridge.Config.Meta.ForceRefreshIntervalSeconds) * time.Second
if refreshInterval > 0 {
user.log.Debug().Msgf("Connection will be refreshed at %s", time.Now().Add(refreshInterval).Format(time.RFC3339))
go func() {
var refreshTimer = time.NewTimer(time.Duration(refreshIntervalSeconds) * time.Second)
var refreshTimer = time.NewTimer(refreshInterval)

<-refreshTimer.C
user.log.Info().Msg("Refreshing connection")
user.Disconnect()
user.Connect()
user.FullReconnect()
}()
}
}
Expand Down

0 comments on commit a984cbd

Please sign in to comment.