Add invalid link reset worker
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
"host": "https://api.real-debrid.com/rest/1.0",
|
"host": "https://api.real-debrid.com/rest/1.0",
|
||||||
"api_key": "realdebrid_key",
|
"api_key": "realdebrid_key",
|
||||||
"folder": "/mnt/remote/realdebrid/__all__/",
|
"folder": "/mnt/remote/realdebrid/__all__/",
|
||||||
|
"download_api_keys": [],
|
||||||
"proxy": "",
|
"proxy": "",
|
||||||
"rate_limit": "250/minute",
|
"rate_limit": "250/minute",
|
||||||
"download_uncached": false,
|
"download_uncached": false,
|
||||||
|
|||||||
@@ -169,7 +169,6 @@ func (c *Cache) refreshDownloadLink(link string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Cache) resetDownloadLinks() {
|
func (c *Cache) resetInvalidLinks() {
|
||||||
c.invalidDownloadLinks = xsync.NewMapOf[string, string]()
|
c.invalidDownloadLinks = xsync.NewMapOf[string, string]()
|
||||||
c.downloadLinks = xsync.NewMapOf[string, downloadLinkCache]()
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ func (c *Cache) Refresh() error {
|
|||||||
// For now, we just want to refresh the listing and download links
|
// For now, we just want to refresh the listing and download links
|
||||||
go c.refreshDownloadLinksWorker()
|
go c.refreshDownloadLinksWorker()
|
||||||
go c.refreshTorrentsWorker()
|
go c.refreshTorrentsWorker()
|
||||||
|
go c.resetInvalidLinksWorker()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,3 +27,49 @@ func (c *Cache) refreshTorrentsWorker() {
|
|||||||
c.refreshTorrents()
|
c.refreshTorrents()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Cache) resetInvalidLinksWorker() {
|
||||||
|
// Calculate time until next 12:00 CET
|
||||||
|
now := time.Now()
|
||||||
|
loc, err := time.LoadLocation("CET")
|
||||||
|
if err != nil {
|
||||||
|
// Fallback if CET timezone can't be loaded
|
||||||
|
c.logger.Error().Err(err).Msg("Failed to load CET timezone, using local time")
|
||||||
|
loc = time.Local
|
||||||
|
}
|
||||||
|
|
||||||
|
nowInCET := now.In(loc)
|
||||||
|
next := time.Date(
|
||||||
|
nowInCET.Year(),
|
||||||
|
nowInCET.Month(),
|
||||||
|
nowInCET.Day(),
|
||||||
|
12, 0, 0, 0,
|
||||||
|
loc,
|
||||||
|
)
|
||||||
|
|
||||||
|
// If it's already past 12:00 CET today, schedule for tomorrow
|
||||||
|
if nowInCET.After(next) {
|
||||||
|
next = next.Add(24 * time.Hour)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Duration until next 12:00 CET
|
||||||
|
initialWait := next.Sub(nowInCET)
|
||||||
|
|
||||||
|
// Set up initial timer
|
||||||
|
timer := time.NewTimer(initialWait)
|
||||||
|
defer timer.Stop()
|
||||||
|
|
||||||
|
c.logger.Debug().Msgf("Scheduled invalid links reset at %s (in %s)", next.Format("2006-01-02 15:04:05 MST"), initialWait)
|
||||||
|
|
||||||
|
// Wait for the first execution
|
||||||
|
<-timer.C
|
||||||
|
c.resetInvalidLinks()
|
||||||
|
|
||||||
|
// Now set up the daily ticker
|
||||||
|
refreshTicker := time.NewTicker(24 * time.Hour)
|
||||||
|
defer refreshTicker.Stop()
|
||||||
|
|
||||||
|
for range refreshTicker.C {
|
||||||
|
c.resetInvalidLinks()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user