Handle Server Unavailable Error from Khoj.el (#568)

- Make auto-update of content index user configurable from khoj.el
- Handle server unavailable error on auto-index schedule job in khoj.el

Resolves #567
This commit is contained in:
Debanjum 2023-11-24 16:46:07 -08:00 committed by GitHub
commit 25f3f2367e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -98,6 +98,11 @@
:group 'khoj
:type 'string)
(defcustom khoj-auto-index t
"Should content be automatically re-indexed every `khoj-index-interval' seconds."
:group 'khoj
:type 'boolean)
(defcustom khoj-index-interval 3600
"Interval (in seconds) to wait before updating content index."
:group 'khoj
@ -405,14 +410,14 @@ Auto invokes setup steps on calling main entrypoint."
;; render response from indexing API endpoint on server
(lambda (status)
(if (not status)
(message "khoj.el: %scontent index %supdated" (if content-type (format "%s " content-type) "") (if force "force " ""))
(message "khoj.el: %scontent index %supdated" (if content-type (format "%s " content-type) "all ") (if force "force " ""))
(with-current-buffer (current-buffer)
(goto-char "\n\n")
(message "khoj.el: Failed to %supdate %s content index. Status: %s. Response: %s"
(search-forward "\n\n" nil t)
(message "khoj.el: Failed to %supdate %s content index. Status: %s%s"
(if force "force " "")
content-type
status
(string-trim (buffer-substring-no-properties (point) (point-max)))))))
(if content-type (format "%s " content-type) "all")
(string-trim (format "%s %s" (nth 1 (nth 1 status)) (nth 2 (nth 1 status))))
(if (> (- (point-max) (point)) 0) (format ". Response: %s" (string-trim (buffer-substring-no-properties (point) (point-max)))) "")))))
nil t t)))
(setq khoj--indexed-files files-to-index)))
@ -444,8 +449,9 @@ Use `BOUNDARY' to separate files. This is sent to Khoj server as a POST request.
(when khoj--index-timer
(cancel-timer khoj--index-timer))
;; Send files to index on server every `khoj-index-interval' seconds
(setq khoj--index-timer
(run-with-timer 60 khoj-index-interval 'khoj--server-index-files))
(when khoj-auto-index
(setq khoj--index-timer
(run-with-timer 60 khoj-index-interval 'khoj--server-index-files)))
;; -------------------------------------------