Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async version check #216

Merged
merged 1 commit into from
Nov 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"))