Try to keep long running sessions from expiring

The function `ein:notebooklist-enable-keepalive` and
`ein:notebooklist-disable-keepalive`, respectively enable a timer that
ocassionally (on the order of hours) sends a query to the notebook server. The
goal is to keep cookies and sessions from expiring in long running notebooks.
We'll see if it works.
This commit is contained in:
John Miller 2017-01-31 10:44:04 -06:00
parent 2615d77a7f
commit 94e334cbf0
3 changed files with 34 additions and 2 deletions

View file

@ -138,7 +138,7 @@ original notebook cell, unless being called via
(ein:remove-overlay)
(when ein:src--allow-write-back
(ein:edit-cell-save))
(ewoc-invalidate (oref ein:src--cell :ewoc)
(ewoc-invalidate (slot-value ein:src--cell 'ewoc)
(ein:cell-element-get cell :input))
(kill-buffer edit-buffer)
(switch-to-buffer-other-window (ein:worksheet--get-buffer ws))

View file

@ -130,7 +130,11 @@ the source is in git repository."
(defvar *running-ipython-version* (make-hash-table))
(defun ein:get-ipython-major-version (vstr)
(string-to-number (car (split-string vstr "\\."))))
(if vstr
(string-to-number (car (split-string vstr "\\.")))
(if (>= ein:log-level (ein:log-level-name-to-int 'debug))
(throw 'error "Null value passed to ein:get-ipython-major-version.")
(ein:log 'warn "Null value passed to ein:get-ipython-major-version."))))
;; TODO: Use symbols instead of numbers for ipython version ('jupyter and 'legacy)?
(defun ein:query-ipython-version (&optional url-or-port force)

View file

@ -166,6 +166,34 @@ To suppress popup, you can pass a function `ein:do-nothing' as CALLBACK."
;(ein:notebooklist-get-buffer url-or-port)
)
(defcustom ein:notebooklist-keepalive-refresh-time 1
"When the notebook keepalive is enabled, the frequency, IN
HOURS, with which to make calls to the jupyter content API to
refresh the notebook connection."
:type 'float
:group 'ein)
(defvar ein:notebooklist--keepalive-timer nil)
;;;###autoload
(defun ein:notebooklist-enable-keepalive (&optional url-or-port)
"Enable periodic calls to the notebook server t"
(interactive (list (ein:notebooklist-ask-url-or-port)))
(let ((success
(lambda (content)
(ein:log 'info "Refreshing notebooklist connection.")))
(refresh-time (* ein:notebooklist-keepalive-refresh-time 60 60)))
(setq ein:notebooklist--keepalive-timer
(run-at-time 0.1 refresh-time #'ein:content-query-contents "" url-or-port nil success))))
;;;###autoload
(defun ein:notebooklist-disable-keepalive ()
""
(interactive)
(cancel-timer ein:notebooklist--keepalive-timer))
(defun* ein:notebooklist-url-retrieve-callback (content)
"Called via `ein:notebooklist-open'."
(let ((url-or-port (ein:$content-url-or-port content))