Skip to content
Snippets Groups Projects
Commit a6b307c1 authored by Tom Robinson's avatar Tom Robinson
Browse files

Initialization progress bar

parent 759f42d0
No related branches found
No related tags found
No related merge requests found
......@@ -5,11 +5,34 @@
<title>Metabase</title>
</head>
<body>
Initializing Metabase, please wait...
<h3>Initializing Metabase, please wait...</h3>
<div>
<progress id="progress" max="100" value="0"></progress>
</div>
<script type="text/javascript">
setTimeout(function() {
window.location.reload();
}, 2500);
function poll() {
var req = new XMLHttpRequest();
req.open("GET", "/api/health", true);
req.onreadystatechange = function() {
if (req.readyState === 4) {
if (req.status === 200) {
window.location.reload();
} else {
try {
var health = JSON.parse(req.responseText);
if (typeof health.progress === "number") {
document.getElementById("progress").value = health.progress * 100;
}
} catch (e) {}
setTimeout(poll, 500);
}
}
}
req.send();
}
poll();
</script>
</body>
</html>
......@@ -37,7 +37,7 @@
(context "/foreignkey" [] (+auth fk/routes))
(GET "/health" [] (if ((resolve 'metabase.core/initialized?))
{:status 200 :body {:status "ok"}}
{:status 503 :body {:status "initializing"}}))
{:status 503 :body {:status "initializing" :progress ((resolve 'metabase.core/initialization-progress))}}))
(context "/notify" [] (+apikey notify/routes))
(context "/revision" [] (+auth revision/routes))
(context "/session" [] session/routes)
......
......@@ -71,13 +71,18 @@
;;; ## ---------------------------------------- LIFECYCLE ----------------------------------------
(def ^:private metabase-initialized
(atom false))
(def ^:private metabase-initialization-progress
(atom 0))
(defn initialized?
"Metabase is initialized and ready to be served"
[]
@metabase-initialized)
(= @metabase-initialization-progress 1.0))
(defn initialization-progress
"Metabase is initialized and ready to be served"
[]
@metabase-initialization-progress)
(defn- -init-create-setup-token
"Create and set a new setup token, and open the setup URL on the user's system."
......@@ -104,11 +109,15 @@
"General application initialization function which should be run once at application startup."
[]
(log/info (format "Starting Metabase version %s..." (config/mb-version-string)))
(reset! metabase-initialization-progress 0.1)
;; First of all, lets register a shutdown hook that will tidy things up for us on app exit
(.addShutdownHook (Runtime/getRuntime) (Thread. ^Runnable destroy))
(reset! metabase-initialization-progress 0.3)
;; startup database. validates connection & runs any necessary migrations
(db/setup-db :auto-migrate (config/config-bool :mb-db-automigrate))
(reset! metabase-initialization-progress 0.5)
;; run a very quick check to see if we are doing a first time installation
;; the test we are using is if there is at least 1 User in the database
......@@ -116,9 +125,11 @@
;; Bootstrap the event system
(events/initialize-events!)
(reset! metabase-initialization-progress 0.7)
;; Now start the task runner
(task/start-scheduler!)
(reset! metabase-initialization-progress 0.8)
(when new-install
(log/info "Looks like this is a new installation ... preparing setup wizard")
......@@ -126,6 +137,7 @@
(-init-create-setup-token)
;; publish install event
(events/publish-event :install {}))
(reset! metabase-initialization-progress 0.9)
;; deal with our sample dataset as needed
(if new-install
......@@ -135,7 +147,7 @@
(sample-data/update-sample-dataset-if-needed!)))
(log/info "Metabase Initialization COMPLETE")
(reset! metabase-initialized true)
(reset! metabase-initialization-progress 1.0)
true)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment