summaryrefslogtreecommitdiff
path: root/scripts/mumi.in
diff options
context:
space:
mode:
authorRicardo Wurmus <rekado@elephly.net>2020-03-12 10:57:47 +0100
committerRicardo Wurmus <rekado@elephly.net>2020-03-12 10:57:47 +0100
commit5d549c5bb793d4186559f77494f0ffce9fa15e61 (patch)
tree1722eebb0528d4154927431dd4edee18b1f4750e /scripts/mumi.in
parent4052368bb5372a9f4c6164ef71d3bcd7ede9e81b (diff)
scripts: Add worker option to refresh database.
* scripts/mumi.in: Update the mu index and the Sqlite database when the "--worker" option is provided.
Diffstat (limited to 'scripts/mumi.in')
-rw-r--r--scripts/mumi.in60
1 files changed, 36 insertions, 24 deletions
diff --git a/scripts/mumi.in b/scripts/mumi.in
index 81cb887..82e2319 100644
--- a/scripts/mumi.in
+++ b/scripts/mumi.in
@@ -28,15 +28,39 @@
(ice-9 match)
(ice-9 threads)
(mumi config)
+ (mumi bugs)
(mumi messages)
(mumi web server)
(debbugs))
+(db-create!)
+
(define %default-repl-server-port
;; Default port to run REPL server on, if --listen-repl is provided
;; but no port is mentioned
37146)
+;; Keep indexing the mail directory
+(define %update-interval 60)
+(define mu-index
+ (let ((mu (%config 'mu-executable)))
+ (lambda _
+ (let* ((maildir (%config 'mail-dir))
+ (args (list "index"
+ "--quiet"
+ (format #f "--muhome=~a" maildir)
+ (format #f "--maildir=~a" maildir))))
+ (unless (zero? (apply system* mu args))
+ (format (current-error-port)
+ "Failed to run `~a'~%" command))))))
+
+(define update-state!
+ (lambda _
+ (mu-index)
+ (update-bug-database!)
+ (sleep %update-interval)
+ (update-state!)))
+
(define %options
;; Specifications of the command-line options
(list (option '("listen-repl") #f #t
@@ -49,12 +73,16 @@
(error "invalid REPL server port" arg)))))
(option '("fetch") #f #f
(lambda (opt name arg result)
- (alist-cons 'fetch #t result)))))
+ (alist-cons 'fetch #t result)))
+ (option '("worker") #f #f
+ (lambda (opt name arg result)
+ (alist-cons 'worker #t result)))))
(define %default-options
;; Alist of default option values
`((listen-repl . #f)
- (fetch . #f)))
+ (fetch . #f)
+ (worker . #f)))
(define (parse-options args)
(args-fold
@@ -67,6 +95,8 @@
(let ((opts (parse-options (cdr (program-arguments)))))
(cond
+ ((assoc-ref opts 'worker)
+ (update-state!))
((assoc-ref opts 'fetch)
(let ((bug-nums
(sort (append-map (lambda (package)
@@ -92,25 +122,7 @@
(else
(let ((repl-port (assoc-ref opts 'listen-repl)))
(when repl-port
- (spawn-server (make-tcp-server-socket #:port repl-port)))))))
-
-;; Keep indexing the mail directory
-(define %mu-index-interval 30)
-(define mu-index
- (let ((mu (%config 'mu-executable)))
- (lambda _
- (let* ((maildir (%config 'mail-dir))
- (args (list "index"
- "--quiet"
- (format #f "--muhome=~a" maildir)
- (format #f "--maildir=~a" maildir))))
- (unless (zero? (apply system* mu args))
- (format (current-error-port)
- "Failed to run `~a'~%" command))
- (alarm %mu-index-interval)))))
-(sigaction SIGALRM mu-index 0)
-(mu-index)
-
-(use-modules (mumimu))
-(mu:initialize (%config 'mail-dir))
-(start-mumi-web-server 1234)
+ (spawn-server (make-tcp-server-socket #:port repl-port))))
+ (use-modules (mumimu))
+ (mu:initialize (%config 'mail-dir))
+ (start-mumi-web-server 1234))))