Skip to content

Commit

Permalink
Async version check
Browse files Browse the repository at this point in the history
  • Loading branch information
notmgsk authored and stylewarning committed Nov 15, 2019
1 parent 4169ff5 commit bd2e7f1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 20 deletions.
11 changes: 3 additions & 8 deletions app/src/entry-point.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -407,14 +407,6 @@ Copyright (c) 2016-2019 Rigetti Computing.~2%")
(when check-libraries
(check-libraries))

(when check-sdk-version
(multiple-value-bind (available-p version)
(sdk-update-available-p +QVM-VERSION+ :proxy proxy)
(when available-p
(format t "An update is available to the SDK. You have version ~A. ~
Version ~A is available from https://www.rigetti.com/forest~%"
+QVM-VERSION+ version))))

(when verbose
(setf qvm:*transition-verbose* t))

Expand Down Expand Up @@ -540,6 +532,9 @@ Version ~A is available from https://www.rigetti.com/forest~%"

;; Server mode.
(server
(when check-sdk-version
(asynchronously-indicate-update-availability +QVM-VERSION+ :proxy proxy))

(when execute
(format-log "Warning: Ignoring execute option: ~S" execute)
(setf execute nil))
Expand Down
42 changes: 30 additions & 12 deletions app/src/qvm-app-version.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
:documentation "The git hash of the QVM repo.")
)

(defun latest-sdk-version (&key (proxy nil))
(declaim (special *logger*))

(defun query-latest-sdk-version (&key (proxy nil))
"Get the latest SDK qvm version, or NIL if unavailable."
(handler-case
(let* ((s (drakma:http-request
Expand All @@ -49,24 +51,40 @@
(when success
version)))
(usocket:ns-error (condition)
(with-locked-log ()
(cl-syslog:rfc-log (*logger* :warning "Encountered a name resolution error when fetching latest SDK version. (~A)" condition)
(:msgid "LOG0001")))
(cl-syslog:rfc-log (*logger* :warning "Encountered a name resolution error when fetching latest SDK version. (~A)" condition)
(:msgid "LOG0001"))
nil)
(usocket:socket-error (condition)
(with-locked-log ()
(cl-syslog:rfc-log (*logger* :warning "Encountered a socket error when fetching latest SDK version. (~A)" condition)
(:msgid "LOG0001")))
(cl-syslog:rfc-log (*logger* :warning "Encountered a socket error when fetching latest SDK version. (~A)" condition)
(:msgid "LOG0001"))
nil)
(sb-bsd-sockets:socket-error (condition)
(with-locked-log ()
(cl-syslog:rfc-log (*logger* :warning "Encountered a socket error when fetching latest SDK version. (~A)" condition)
(:msgid "LOG0001")))
(cl-syslog:rfc-log (*logger* :warning "Encountered a socket error when fetching latest SDK version. (~A)" condition)
(:msgid "LOG0001"))
nil)))

(defun sdk-update-available-p (current-version &key (proxy nil))
"Test whether the current QVM version is the latest SDK
"Test whether the current SDK version is the latest SDK
version. Second value returned indicates the latest version."
(let ((latest (latest-sdk-version :proxy proxy)))
(let ((latest (query-latest-sdk-version :proxy proxy)))
(values (and latest (uiop:version< current-version latest))
latest)))

(defun asynchronously-indicate-update-availability (current-version &key (proxy nil))
"Write to the logger the state of the software version (whether it's the latest, if there's an update, if an update couldn't be queried)."
(bt:make-thread
(lambda ()
(multiple-value-bind (available? latest) (sdk-update-available-p current-version :proxy proxy)
(cond
((null latest)
;; There was some kind of issue getting the version and a warning was already emitted.
)
((not available?)
(cl-syslog:rfc-log (*logger* :info "This is the latest version of the SDK.")
(:msgid "LOG0001")))
(available?
(cl-syslog:rfc-log (*logger* :notice "An update is available to the SDK. You have version ~A. ~
Version ~A is available from https://downloads.rigetti.com/~%"
+QVM-VERSION+ latest)
(:msgid "LOG0001"))))))
:name "Version Check"))

0 comments on commit bd2e7f1

Please sign in to comment.