From 0885fc6c230f95642353f2d67e23aec92325f05f Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Fri, 24 Nov 2023 16:39:44 -0800 Subject: [PATCH 1/2] Handle server unavailable error on auto-index schedule job in khoj.el --- src/interface/emacs/khoj.el | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/interface/emacs/khoj.el b/src/interface/emacs/khoj.el index 001f7c41..762e85e7 100644 --- a/src/interface/emacs/khoj.el +++ b/src/interface/emacs/khoj.el @@ -405,14 +405,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))) From 138f4e3f3c5e85b57e5a40b6e46449fed6d0fbd0 Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Fri, 24 Nov 2023 16:40:50 -0800 Subject: [PATCH 2/2] Make auto-update of content index user configurable from khoj.el --- src/interface/emacs/khoj.el | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/interface/emacs/khoj.el b/src/interface/emacs/khoj.el index 762e85e7..dfaf34b7 100644 --- a/src/interface/emacs/khoj.el +++ b/src/interface/emacs/khoj.el @@ -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 @@ -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))) ;; -------------------------------------------