Add --threads option to 'doom update' #1736

This commit is contained in:
Henrik Lissner 2019-09-12 17:22:17 -04:00
parent 3e3808aa8d
commit 84837fa0d6
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -19,11 +19,17 @@ This works by fetching all installed package repos and checking the distance
between HEAD and FETCH_HEAD. This can take a while. between HEAD and FETCH_HEAD. This can take a while.
This excludes packages whose `package!' declaration contains a non-nil :freeze This excludes packages whose `package!' declaration contains a non-nil :freeze
or :ignore property." or :ignore property.
Switches:
-t/--timeout TTL Seconds until a thread is timed out (default: 45)
--threads N How many threads to use (default: 8)"
(doom--ensure-autoloads-while (doom--ensure-autoloads-while
(straight-check-all) (straight-check-all)
(doom-packages-update (doom-packages-update
doom-auto-accept doom-auto-accept
(when-let (threads (cadr (member "--threads" args)))
(string-to-number threads))
(when-let (timeout (cadr (or (member "--timeout" args) (when-let (timeout (cadr (or (member "--timeout" args)
(member "-t" args)))) (member "-t" args))))
(string-to-number timeout))))) (string-to-number timeout)))))
@ -213,7 +219,7 @@ a list of packages that will be installed."
(cons 'error e)))))) (cons 'error e))))))
(defun doom-packages-update (&optional auto-accept-p timeout) (defun doom-packages-update (&optional auto-accept-p threads timeout)
"Updates packages. "Updates packages.
Unless AUTO-ACCEPT-P is non-nil, this function will prompt for confirmation with Unless AUTO-ACCEPT-P is non-nil, this function will prompt for confirmation with
@ -222,14 +228,17 @@ a list of packages that will be updated."
(print-group! (print-group!
(when timeout (when timeout
(print! (info "Using %S as timeout value" timeout))) (print! (info "Using %S as timeout value" timeout)))
(when threads
(print! (info "Limiting to %d thread(s)" threads)))
;; REVIEW Does this fail gracefully enough? Is it error tolerant? ;; REVIEW Does this fail gracefully enough? Is it error tolerant?
;; TODO Add version-lock checks; don't want to spend all this effort on ;; TODO Add version-lock checks; don't want to spend all this effort on
;; packages that shouldn't be updated ;; packages that shouldn't be updated
(let* ((futures (let* ((futures
;; REVIEW We can do better "thread" management here
(or (cl-loop for group (or (cl-loop for group
in (seq-partition (hash-table-values straight--repo-cache) in (seq-partition (hash-table-values straight--repo-cache)
(/ (hash-table-count straight--repo-cache) (/ (hash-table-count straight--repo-cache)
16)) (or threads 8)))
for future = (doom--packages-remove-outdated-f group) for future = (doom--packages-remove-outdated-f group)
if (processp future) if (processp future)
collect (cons future group) collect (cons future group)