Made refresh time for feed queries configurable.

This commit is contained in:
Martin Dosch 2018-09-05 20:40:41 +02:00
parent 7e2c58256d
commit e0d4613023
3 changed files with 15 additions and 2 deletions

View file

@ -45,8 +45,14 @@ If the flag `-config` is not used the configuration is expected at
"Muc": "muc-to-feed@conference.example.com", "Muc": "muc-to-feed@conference.example.com",
"MucNick": "feedbot", "MucNick": "feedbot",
"MaxArticles": 5, "MaxArticles": 5,
"RefreshTime": 30,
"NoExcerpt": false, "NoExcerpt": false,
"Feeds": [ "https://www.debian.org/News/news", "Feeds": [ "https://www.debian.org/News/news",
"https://www.debian.org/security/dsa-long" ] "https://www.debian.org/security/dsa-long" ]
} }
``` ```
`MaxArticles` is the maximum number of articles that are sent per
feed and query. If `NoExcerpt` is set to *true* no excerpt will be
posted. `RefreshTime` defines the intervall for checking the feeds
in seconds.

View file

@ -5,6 +5,7 @@
"Muc": "muc-to-feed@conference.example.com", "Muc": "muc-to-feed@conference.example.com",
"MucNick": "feedbot", "MucNick": "feedbot",
"MaxArticles": 5, "MaxArticles": 5,
"RefreshTime": 30,
"NoExcerpt": false, "NoExcerpt": false,
"Feeds": [ "https://www.debian.org/News/news", "Feeds": [ "https://www.debian.org/News/news",
"https://www.debian.org/security/dsa-long" ] "https://www.debian.org/security/dsa-long" ]

View file

@ -36,6 +36,7 @@ func main() {
Muc string Muc string
MucNick string MucNick string
MaxArticles int MaxArticles int
RefreshTime time.Duration
NoExcerpt bool NoExcerpt bool
Feeds []string Feeds []string
} }
@ -144,6 +145,11 @@ func main() {
// Starting goroutine to process received stanzas. // Starting goroutine to process received stanzas.
go processStanzas(client) go processStanzas(client)
// Set RefreshTime to 30 seconds if not defined.
if config.RefreshTime == 0 {
config.RefreshTime = 30
}
for { for {
// Check all configured feeds for new articles and send // Check all configured feeds for new articles and send
// new articles to configured MUC. // new articles to configured MUC.
@ -165,7 +171,7 @@ func main() {
} }
} }
// Wait 30 seconds before checking feeds again. // Wait 30 seconds before checking feeds again.
time.Sleep(30 * time.Second) time.Sleep(config.RefreshTime * time.Second)
} }
} }