mirror of
https://github.com/makeworld-the-better-one/amfora.git
synced 2024-11-22 15:46:51 +03:00
Update every X minutes with X workers
This commit is contained in:
parent
d0d8b15bbb
commit
12321f82a7
@ -230,11 +230,13 @@ func Init() error {
|
||||
viper.SetDefault("a-general.page_max_size", 2097152)
|
||||
viper.SetDefault("a-general.page_max_time", 10)
|
||||
viper.SetDefault("a-general.emoji_favicons", false)
|
||||
viper.SetDefault("a-general.feed_popup", true)
|
||||
viper.SetDefault("keybindings.shift_numbers", "!@#$%^&*()")
|
||||
viper.SetDefault("url-handlers.other", "off")
|
||||
viper.SetDefault("cache.max_size", 0)
|
||||
viper.SetDefault("cache.max_pages", 20)
|
||||
viper.SetDefault("feeds.popup", true)
|
||||
viper.SetDefault("feeds.update_interval", 1800)
|
||||
viper.SetDefault("feeds.workers", 3)
|
||||
|
||||
viper.SetConfigFile(configPath)
|
||||
viper.SetConfigType("toml")
|
||||
|
@ -68,9 +68,6 @@ page_max_time = 10
|
||||
# Whether to replace tab numbers with emoji favicons, which are cached.
|
||||
emoji_favicons = false
|
||||
|
||||
# Whether a pop-up appears when viewing a potential feed
|
||||
feed_popup = true
|
||||
|
||||
|
||||
[auth]
|
||||
# Authentication settings
|
||||
@ -134,6 +131,25 @@ max_pages = 30 # The maximum number of pages the cache will store
|
||||
# Note that HTTP and HTTPS are treated as separate protocols here.
|
||||
|
||||
|
||||
[feeds]
|
||||
# For tracking feeds and pages
|
||||
|
||||
# Whether a pop-up appears when viewing a potential feed
|
||||
popup = true
|
||||
|
||||
# How often to check for new feeds and pages in the background, in seconds.
|
||||
# Note Amfora will check for updates on browser start anyway.
|
||||
# Set it to 0 or below to disable this feature. You can still update individual
|
||||
# feeds manually, or just restart the browser to update all of them.
|
||||
update_interval = 1800 # 30 mins
|
||||
|
||||
# How many pages/feeds can be checked at the same time when updating.
|
||||
# If you are tracking many feeds and pages you may want to increase this for
|
||||
# faster update times.
|
||||
# Any value below 1 will be corrected to 1.
|
||||
workers = 3
|
||||
|
||||
|
||||
[theme]
|
||||
# This section is for changing the COLORS used in Amfora.
|
||||
# These colors only apply if 'color' is enabled above.
|
||||
|
@ -65,9 +65,6 @@ page_max_time = 10
|
||||
# Whether to replace tab numbers with emoji favicons, which are cached.
|
||||
emoji_favicons = false
|
||||
|
||||
# Whether a pop-up appears when viewing a potential feed
|
||||
feed_popup = true
|
||||
|
||||
|
||||
[auth]
|
||||
# Authentication settings
|
||||
@ -131,6 +128,25 @@ max_pages = 30 # The maximum number of pages the cache will store
|
||||
# Note that HTTP and HTTPS are treated as separate protocols here.
|
||||
|
||||
|
||||
[feeds]
|
||||
# For tracking feeds and pages
|
||||
|
||||
# Whether a pop-up appears when viewing a potential feed
|
||||
popup = true
|
||||
|
||||
# How often to check for new feeds and pages in the background, in seconds.
|
||||
# Note Amfora will check for updates on browser start anyway.
|
||||
# Set it to 0 or below to disable this feature. You can still update individual
|
||||
# feeds manually, or just restart the browser to update all of them.
|
||||
update_interval = 1800 # 30 mins
|
||||
|
||||
# How many pages/feeds can be checked at the same time when updating.
|
||||
# If you are tracking many feeds and pages you may want to increase this for
|
||||
# faster update times.
|
||||
# Any value below 1 will be corrected to 1.
|
||||
workers = 3
|
||||
|
||||
|
||||
[theme]
|
||||
# This section is for changing the COLORS used in Amfora.
|
||||
# These colors only apply if 'color' is enabled above.
|
||||
|
@ -43,8 +43,9 @@ func Feeds(t *tab) {
|
||||
|
||||
logger.Log.Println("started rendering feeds page")
|
||||
|
||||
feedPageRaw := "# Feeds & Pages\n\nUpdates" + strings.Repeat(" ", 80-25) + "[Newest -> Oldest]\n" +
|
||||
strings.Repeat("-", 80) + "\nSee the help (by pressing ?) for details on how to use this page.\n\n"
|
||||
feedPageRaw := "# Feeds & Pages\n\n" +
|
||||
"See the help (by pressing ?) for details on how to use this page.\n\n" +
|
||||
"If you just opened Amfora then updates will appear incrementally. Reload the page to see them.\n"
|
||||
|
||||
// curDay represents what day of posts the loop is on.
|
||||
// It only goes backwards in time.
|
||||
|
@ -338,7 +338,7 @@ func handleURL(t *tab, u string, numRedirects int) (string, bool) {
|
||||
t.mode = tabModeDone
|
||||
|
||||
go func(p *structs.Page) {
|
||||
if b && t.hasContent() && !feeds.IsTracked(s) && viper.GetBool("a-general.feed_popup") {
|
||||
if b && t.hasContent() && !feeds.IsTracked(s) && viper.GetBool("feeds.popup") {
|
||||
// The current page might be an untracked feed, and the user wants
|
||||
// to be notified in such cases.
|
||||
|
||||
|
@ -21,6 +21,7 @@ import (
|
||||
"github.com/makeworld-the-better-one/amfora/logger"
|
||||
"github.com/makeworld-the-better-one/go-gemini"
|
||||
"github.com/mmcdole/gofeed"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
// TODO: Test for deadlocks and whether there should be more
|
||||
@ -60,7 +61,21 @@ func Init() error {
|
||||
}
|
||||
|
||||
LastUpdated = time.Now()
|
||||
go updateAll()
|
||||
|
||||
if viper.GetInt("feeds.update_interval") > 0 {
|
||||
// Update feeds and pages every so often
|
||||
go func() {
|
||||
for {
|
||||
updateAll()
|
||||
time.Sleep(time.Duration(viper.GetInt("feeds.update_interval")) * time.Second)
|
||||
}
|
||||
}()
|
||||
} else {
|
||||
// User disabled automatic feed/page updates
|
||||
// So just update once at the beginning
|
||||
go updateAll()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -288,8 +303,13 @@ func updateAll() {
|
||||
return
|
||||
}
|
||||
|
||||
// Start 2 workers, waiting for jobs
|
||||
for w := 0; w < 2; w++ {
|
||||
numWorkers := viper.GetInt("feed.workers")
|
||||
if numWorkers < 1 {
|
||||
numWorkers = 1
|
||||
}
|
||||
|
||||
// Start workers, waiting for jobs
|
||||
for w := 0; w < numWorkers; w++ {
|
||||
wg.Add(1)
|
||||
go func(i int) {
|
||||
logger.Log.Println("started worker", i)
|
||||
|
Loading…
Reference in New Issue
Block a user