generated from alecodes/base-template
feat: archive read entries
This commit is contained in:
parent
43f6340a4a
commit
1788241cd5
1 changed files with 41 additions and 6 deletions
|
|
@ -1,13 +1,34 @@
|
|||
package app
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"git.alecodes.page/alecodes/miniflux-archiver/internal/logger"
|
||||
"git.alecodes.page/alecodes/miniflux-archiver/internal/miniflux"
|
||||
"git.alecodes.page/alecodes/miniflux-archiver/internal/service"
|
||||
)
|
||||
|
||||
// NewRateLimiter creates a rate limiter that emits time events at a specified rate.
|
||||
// request_per specifies the number of requests allowed per time_scale duration.
|
||||
// time_scale specifies the duration over which the requests are allowed.
|
||||
func newRateLimiter(request_per int, time_scale time.Duration) <-chan time.Time {
|
||||
rate_limit := make(chan time.Time, request_per)
|
||||
tickrate := time_scale / time.Duration(request_per)
|
||||
|
||||
for range request_per {
|
||||
rate_limit <- time.Now()
|
||||
}
|
||||
|
||||
go func() {
|
||||
for t := range time.Tick(tickrate) {
|
||||
rate_limit <- t
|
||||
}
|
||||
}()
|
||||
|
||||
return rate_limit
|
||||
}
|
||||
|
||||
func Archive(minifluxConfig miniflux.MinifluxConfig, serviceConfig service.ServiceConfig) {
|
||||
mf, err := miniflux.NewMiniflux(minifluxConfig)
|
||||
if err != nil {
|
||||
|
|
@ -24,11 +45,25 @@ func Archive(minifluxConfig miniflux.MinifluxConfig, serviceConfig service.Servi
|
|||
logger.Fatal("Could not retrieve entries from the miniflux feed: %v", err)
|
||||
}
|
||||
|
||||
entry := result.Entries[0]
|
||||
fmt.Println(entry.Title, entry.Status, entry.Tags)
|
||||
var wg sync.WaitGroup
|
||||
ticker := newRateLimiter(5, 10*time.Second)
|
||||
|
||||
err = externalService.Archive(entry.URL)
|
||||
if err != nil {
|
||||
logger.Fatal("Could not archive entry from the service: %v", err)
|
||||
for _, entry := range result.Entries {
|
||||
wg.Add(1)
|
||||
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
<-ticker
|
||||
|
||||
// logger.Debug("Sending url \"%v\" to be marked as read", entry.URL)
|
||||
err := externalService.Archive(entry.URL)
|
||||
if err != nil {
|
||||
logger.Fatal("Could not archive url \"%v\" from the service: %v", entry.URL, err)
|
||||
}
|
||||
|
||||
logger.Info("Url \"%v\" has been marked as read", entry.URL)
|
||||
}()
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue