From b5faa6bbb23215fb5839bf3ff6064d3f8f4122b7 Mon Sep 17 00:00:00 2001 From: Jan-Lukas Else Date: Mon, 24 May 2021 10:44:43 +0200 Subject: [PATCH] Only wait with queue processing if queue is empty --- activityPub.go | 4 +--- activityPubSending.go | 11 ++++------- main.go | 5 +---- webmention.go | 4 ++-- webmentionVerification.go | 11 ++++------- 5 files changed, 12 insertions(+), 23 deletions(-) diff --git a/activityPub.go b/activityPub.go index 5ff56ca..9fe4615 100644 --- a/activityPub.go +++ b/activityPub.go @@ -80,9 +80,7 @@ func initActivityPub() error { return err } // Init send queue - if err = initAPSendQueue(); err != nil { - return err - } + initAPSendQueue() return nil } diff --git a/activityPubSending.go b/activityPubSending.go index 3d51daa..513d73a 100644 --- a/activityPubSending.go +++ b/activityPubSending.go @@ -19,15 +19,9 @@ type apRequest struct { Try int } -func initAPSendQueue() (err error) { - startAPSendQueue() - return nil -} - -func startAPSendQueue() { +func initAPSendQueue() { go func() { for { - time.Sleep(3 * time.Second) qi, err := peekQueue("ap") if err != nil { log.Println(err.Error()) @@ -56,6 +50,9 @@ func startAPSendQueue() { if err != nil { log.Println(err.Error()) } + } else { + // No item in the queue, wait a moment + time.Sleep(15 * time.Second) } } }() diff --git a/main.go b/main.go index 5312110..bbea259 100644 --- a/main.go +++ b/main.go @@ -130,10 +130,7 @@ func main() { logErrAndQuit("Failed to init ActivityPub:", err.Error()) return } - if err = initWebmention(); err != nil { - logErrAndQuit("Failed to init webmention support:", err.Error()) - return - } + initWebmention() initTelegram() initBlogStats() initSessions() diff --git a/webmention.go b/webmention.go index f5d0a19..4c364fd 100644 --- a/webmention.go +++ b/webmention.go @@ -30,7 +30,7 @@ type mention struct { Status webmentionStatus } -func initWebmention() error { +func initWebmention() { // Add hooks hookFunc := func(p *post) { if p.Status == statusPublished { @@ -41,7 +41,7 @@ func initWebmention() error { postHooks[postUpdateHook] = append(postHooks[postUpdateHook], hookFunc) postHooks[postDeleteHook] = append(postHooks[postDeleteHook], hookFunc) // Start verifier - return initWebmentionQueue() + initWebmentionQueue() } func handleWebmention(w http.ResponseWriter, r *http.Request) { diff --git a/webmentionVerification.go b/webmentionVerification.go index acc1bd9..6415199 100644 --- a/webmentionVerification.go +++ b/webmentionVerification.go @@ -20,15 +20,9 @@ import ( "willnorris.com/go/microformats" ) -func initWebmentionQueue() (err error) { - startWebmentionQueue() - return nil -} - -func startWebmentionQueue() { +func initWebmentionQueue() { go func() { for { - time.Sleep(10 * time.Second) qi, err := peekQueue("wm") if err != nil { log.Println(err.Error()) @@ -49,6 +43,9 @@ func startWebmentionQueue() { if err != nil { log.Println(err.Error()) } + } else { + // No item in the queue, wait a moment + time.Sleep(15 * time.Second) } } }()