mirror of
https://github.com/qdm12/ddns-updater.git
synced 2026-08-11 04:15:40 -04:00
- `LOGGING` environment variable `json` or `human` - `NODEID` environment variable (integer) - Much cleaner go code - Listener for exit of program to do cleanup - All code is in packages except main.go - Custom logger package added - Connectivity checks reworked - Healthcheck server on localhost only, so not exposed to outside world - Updated `go.mod` and `go.sum`
52 lines
1.1 KiB
Go
52 lines
1.1 KiB
Go
package update
|
|
|
|
import (
|
|
"time"
|
|
"net/http"
|
|
"ddns-updater/pkg/logging"
|
|
"ddns-updater/pkg/models"
|
|
"ddns-updater/pkg/database"
|
|
)
|
|
|
|
// TriggerServer runs an infinite asynchronous periodic function that triggers updates
|
|
func TriggerServer(
|
|
delay time.Duration,
|
|
forceCh, quitCh chan struct{},
|
|
recordsConfigs []models.RecordConfigType,
|
|
httpClient *http.Client,
|
|
sqlDb *database.DB,
|
|
) {
|
|
ticker := time.NewTicker(delay * time.Second)
|
|
defer func() {
|
|
ticker.Stop()
|
|
close(quitCh)
|
|
}()
|
|
for {
|
|
select {
|
|
case <-ticker.C:
|
|
for i := range recordsConfigs {
|
|
go update(&recordsConfigs[i], httpClient, sqlDb)
|
|
}
|
|
case <-forceCh:
|
|
for i := range recordsConfigs {
|
|
go update(&recordsConfigs[i], httpClient, sqlDb)
|
|
}
|
|
case <-quitCh:
|
|
for {
|
|
allUpdatesFinished := true
|
|
for i := range recordsConfigs {
|
|
if recordsConfigs[i].Status.Code == models.UPDATING {
|
|
allUpdatesFinished = false
|
|
}
|
|
}
|
|
if allUpdatesFinished {
|
|
break
|
|
}
|
|
logging.Info("Waiting for updates to complete...")
|
|
time.Sleep(400 * time.Millisecond)
|
|
}
|
|
ticker.Stop()
|
|
return
|
|
}
|
|
}
|
|
} |