From 2cd16124f8cd1f3ff527b37cb7d18a7b818841af Mon Sep 17 00:00:00 2001 From: nytpu Date: Tue, 23 Mar 2021 08:12:53 -0600 Subject: [PATCH] add timeout flag to refresh --- comitium.go | 1 + core/core.go | 7 ++++++- doc/comitium.1.scd | 10 ++++++++-- flags.go | 5 +++++ 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/comitium.go b/comitium.go index fcf2ae0..0fffb58 100644 --- a/comitium.go +++ b/comitium.go @@ -56,6 +56,7 @@ func main() { switch os.Args[1] { case "refresh": argCheck(c.Args(), 0, false, "'refresh' doesn't take an argument!") + core.Timeout = *refreshTimeoutFlag fetch.RefreshAll(&core.Data, *refreshWorkersFlag) case "regenerate": argCheck(c.Args(), 0, false, "'regenerate' doesn't take an argument!") diff --git a/core/core.go b/core/core.go index f3d88ff..b7d1858 100644 --- a/core/core.go +++ b/core/core.go @@ -28,10 +28,13 @@ var Data = FullData{ // Maps are created in init() } -// the header of feeds.gmi. +// the Header of feeds.gmi. // set in Init, either to the contents of header.gmi or to the default string var Header string +// Timeout for requests +var Timeout int + // have to do this instead of the automatically called init() because // initialization stuff requires parsing of command line args first func Init(dataPath string) error { @@ -88,6 +91,8 @@ func Init(dataPath string) error { ` } + Timeout = 10 + return nil } diff --git a/doc/comitium.1.scd b/doc/comitium.1.scd index 607d911..0d12540 100644 --- a/doc/comitium.1.scd +++ b/doc/comitium.1.scd @@ -33,7 +33,7 @@ variety of feed formats: automatically picked depending on the feed type. For Gemini feeds, the first heading on a page is used as a title. For ATOM, RSS, and JSON feeds, the provided title is used. For a page being watched for changes, the URL - itself is used. + itself is used. Use *-w* to watch a page for changes. Also to note: when adding a new subscription, you *do not* need to run *refresh* afterwards, *add* will automatically fetch the entries and regenerate the .gmi and .json files. @@ -68,6 +68,10 @@ command-specific flags that are not universally recognized. the servers you're hitting and to other people on your network. Defaults to 5. +*-t* _NUM_, *--timeout* _NUM_ + Set a timeout for requests, in seconds. Defaults to 10 seconds per + request. + ## ADD FLAGS *-w*, *--watch* @@ -115,7 +119,9 @@ Within the data directory, the following files are used: *header.gmi* This file is neither created nor modified by comitium. If it exists and is nonempty, then it is read and used as custom header for *feed.gmi*. If it - doesn't exist or is empty, then a default header is used. + doesn't exist or is empty, then a default header is used. The generated + contents of *feed.gmi* will be appended to the contents of *header.gmi* + separated by one newline. *feed.gmi* The outputted text/gemini file containing the subscription items. Is what diff --git a/flags.go b/flags.go index 5fcba98..3967da8 100644 --- a/flags.go +++ b/flags.go @@ -52,6 +52,11 @@ var ( `Number of worker threads to use when refreshing feeds. More is faster, but there are more concurrent outgoing requests then.`, ) + refreshTimeoutFlag = commands["refresh"].IntP( + "timeout", "t", + 10, + `Set a timeout for requests, in seconds.`, + ) // remove removeFeedsFlag = commands["remove"].BoolP(