3 Commits

Author SHA1 Message Date
0d14d50a9f fix: do not fail when a record cannot be updated
All checks were successful
CI / test (pull_request) Successful in 50s
2024-12-27 19:54:00 +01:00
381cf9a750 fix: do not fail when a notification cannot be sent 2024-12-27 19:53:46 +01:00
df6c48b875 fix: do not fail when a record can not be retrieved 2024-12-27 19:53:31 +01:00
4 changed files with 42 additions and 87 deletions

View File

@@ -1,23 +0,0 @@
name: CodeQL Analysis
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
codeql-analysis:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: "go"
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3

View File

@@ -38,7 +38,6 @@ domains:
- www
check_interval: 0 0 0/6 * * * *
mode: Scheduled
log_level: info
```
The config file is expected to be in the same directory as the binary and called `config.yaml`. For the OCR image, the root directory is `/app`.

View File

@@ -21,4 +21,3 @@ domains:
- www
check_interval: 0 0 0/6 * * * *
mode: Scheduled
log_level: info

View File

@@ -3,7 +3,6 @@ package realDynDns
import (
"fmt"
"log/slog"
"sync"
"time"
"realdnydns/pkg/config"
@@ -71,17 +70,10 @@ func (c *ChangeDetector) detectAndApplyChanges() (int, error) {
return 0, err
}
var wg sync.WaitGroup
numberUpdatedChannel := make(chan int)
var numberUpdated int
for _, domain := range c.domains {
for _, subdomain := range domain.Subdomains {
wg.Add(1)
go func(domain config.DomainConfig, subdomain string) {
defer wg.Done()
c.logger.Info("Checking record",
slog.String("tld", domain.TLD),
slog.String("subdomain", subdomain),
@@ -93,7 +85,7 @@ func (c *ChangeDetector) detectAndApplyChanges() (int, error) {
slog.String("tld", domain.TLD),
slog.String("subdomain", subdomain),
)
return
continue
}
if currentRecord.IP != externalIp.String() {
@@ -112,7 +104,7 @@ func (c *ChangeDetector) detectAndApplyChanges() (int, error) {
c.logger.Warn("Failed to send notification",
slog.String("error", err.Error()),
)
return
continue
}
c.logger.Info("Updating record",
@@ -128,23 +120,11 @@ func (c *ChangeDetector) detectAndApplyChanges() (int, error) {
slog.String("tld", domain.TLD),
slog.String("subdomain", subdomain),
)
return
continue
}
numberUpdatedChannel <- 1
}
}(domain, subdomain)
numberUpdated++
}
}
go func() {
wg.Wait()
close(numberUpdatedChannel)
}()
numberUpdated := 0
for v := range numberUpdatedChannel {
numberUpdated += v
}
c.logger.Info("Run completed", slog.Int("number_of_changes", numberUpdated))