scripts: Fetch messages regularly.
authorRicardo Wurmus <rekado@elephly.net>
Tue, 31 Mar 2020 14:16:54 +0000 (16:16 +0200)
committerRicardo Wurmus <rekado@elephly.net>
Tue, 31 Mar 2020 14:16:54 +0000 (16:16 +0200)
scripts/mumi.in

index e0a4d1aa3ca05bd63d5e97e6b20d4f7ec9c28cdc..ac2eb9ba0efe7adf05df7715a1a7f8528f11bfe2 100644 (file)
           (format (current-error-port)
                   "Failed to index `~a'~%" (%config 'mail-dir)))))))
 
+(define (fetch-messages!)
+  (let ((bug-nums
+         (sort (append-map (lambda (package)
+                             (soap-invoke* (%config 'debbugs)
+                                           get-bugs
+                                           `((package . ,package))))
+                           (%config 'packages)) <)))
+    (for-each (lambda (bug-num i)
+                (let ((msg-nums
+                       (match (soap-invoke* (%config 'debbugs)
+                                            get-bug-message-numbers
+                                            bug-num)
+                         ((nums . ids) nums))))
+                  (format (current-error-port)
+                          "[~a/~a] Refreshing ~a messages of bug ~a...~%"
+                          i (length bug-nums)
+                          (length msg-nums) bug-num)
+                  (parameterize ((current-error-port (%make-void-port OPEN_WRITE)))
+                    (par-for-each (cut download-message bug-num <>)
+                                  msg-nums))))
+              bug-nums
+              (iota (length bug-nums) 1))))
+
 (define update-state!
   (lambda _
     (catch #t
       (lambda ()
+        (fetch-messages!)
         (mu-index)
         (update-bug-database!)
         (sleep %update-interval)
    ((assoc-ref opts 'worker)
     (update-state!))
    ((assoc-ref opts 'fetch)
-    (let ((bug-nums
-           (sort (append-map (lambda (package)
-                               (soap-invoke (%config 'debbugs)
-                                            get-bugs
-                                            `((package . ,package))))
-                             (%config 'packages)) <)))
-      (for-each (lambda (bug-num i)
-                  (let ((msg-nums
-                         (match (soap-invoke (%config 'debbugs)
-                                             get-bug-message-numbers
-                                             bug-num)
-                           ((nums . ids) nums))))
-                    (format (current-error-port)
-                            "[~a/~a] Downloading ~a messages of bug ~a...~%"
-                            i (length bug-nums)
-                            (length msg-nums) bug-num)
-                    (parameterize ((current-error-port (%make-void-port OPEN_WRITE)))
-                      (par-for-each (cut download-message bug-num <>)
-                                    msg-nums))))
-                bug-nums
-                (iota (length bug-nums) 1))))
+    (fetch-messages!))
    (else
     (let ((repl-port (assoc-ref opts 'listen-repl)))
       (when repl-port