layed out goroutine

This commit is contained in:
Hazel Noack
2025-07-16 16:59:40 +02:00
parent a0133e0981
commit 6ee6c9c8d9
4 changed files with 21 additions and 3 deletions

View File

@@ -1,7 +1,9 @@
package diyhrt
type DiyHrtConfig struct {
ApiKey string
ApiKey string
FetchIntervals int
StoreFilter StoreFilter
ListingFilter ListingFilter
}

View File

@@ -63,7 +63,8 @@ func NewConfig() Config {
Port: 5500,
},
DiyHrt: diyhrt.DiyHrtConfig{
ApiKey: os.Getenv("API_KEY"),
ApiKey: os.Getenv("API_KEY"),
FetchIntervals: 60, // fetch every hour
StoreFilter: diyhrt.StoreFilter{
Limit: 0,
IncludeIds: []int{7},

View File

@@ -4,6 +4,7 @@ import (
"log"
"net/http"
"strconv"
"time"
"gitea.elara.ws/Hazel/transfem-startpage/internal/cache"
"gitea.elara.ws/Hazel/transfem-startpage/internal/rendering"
@@ -12,12 +13,26 @@ import (
var Config = rendering.NewConfig()
func StartFetching() {
for {
log.Println("Fetch DiyHrt data...")
Config.FetchDiyHrt()
time.Sleep(time.Duration(Config.DiyHrt.FetchIntervals) * time.Second)
if Config.DiyHrt.FetchIntervals == 0 {
break
}
}
}
func Start(profile string) error {
err := Config.ScanForConfigFile(profile)
if err != nil {
return err
}
go StartFetching()
err = Config.FetchDiyHrt()
if err != nil {
log.Println(err)