Skip to content
Snippets Groups Projects
Unverified Commit b0e5822f authored by Cam Saul's avatar Cam Saul Committed by GitHub
Browse files

Fix race conditions when loading drivers (part 2) (#17368)

* Fix race conditions when loading drivers (part 2)

* Test fixes & code cleanup
parent 90930dc6
No related branches found
No related tags found
No related merge requests found
......@@ -206,5 +206,5 @@
(when-not (initialized? driver)
(log/info (u/format-color 'yellow (trs "Initializing driver {0}..." driver)))
(log/debug (trs "Reason:") (u/pprint-to-str 'blue (drop 5 (u/filtered-stacktrace (Thread/currentThread)))))
(swap! initialized-drivers conj driver)
(init-fn driver))))))
(init-fn driver)
(swap! initialized-drivers conj driver))))))
(ns metabase.plugins
(:require [clojure.java.io :as io]
(:require [clojure.java.classpath :as classpath]
[clojure.java.io :as io]
[clojure.string :as str]
[clojure.tools.logging :as log]
[environ.core :as env]
......@@ -9,7 +10,8 @@
[metabase.util.files :as files]
[metabase.util.i18n :refer [trs]]
[yaml.core :as yaml])
(:import [java.nio.file Files Path]))
(:import java.io.File
[java.nio.file Files Path]))
(defn- plugins-dir-filename ^String []
(or (env/env :mb-plugins-dir)
......@@ -107,18 +109,25 @@
(defn- load-local-plugin-manifest! [^Path path]
(some-> (slurp (str path)) yaml.core/parse-string initialize/init-plugin-with-info!))
(defn- driver-manifest-paths []
(filter
files/exists?
(concat
(for [path (files/files-seq (files/get-path "modules/drivers/"))]
(files/get-path (str path) "/resources/metabase-plugin.yaml"))
;; for hacking on 3rd-party drivers locally: set
;; `-Dmb.dev.additional.driver.manifest.paths=/path/to/whatever/metabase-plugin.yaml` or
;; `MB_DEV_ADDITIONAL_DRIVER_MANIFEST_PATHS=...` to have that plugin manifest get loaded during startup. Specify
;; multiple plugin manifests by comma-separating them.
(when-let [additional-paths (env/env :mb-dev-additional-driver-manifest-paths)]
(map files/get-path (str/split additional-paths #","))))))
(defn- driver-manifest-paths
"Return a sequence of [[java.io.File]] paths for `metabase-plugin.yaml` plugin manifests for drivers on the classpath."
[]
;; only include plugin manifests if they're on the system classpath.
(concat
(for [^File file (classpath/system-classpath)
:when (and (.isDirectory file)
(not (.isHidden file))
(str/includes? (str file) "modules/drivers")
(str/ends-with? (str file) "resources"))
:let [manifest-file (io/file file "metabase-plugin.yaml")]
:when (.exists manifest-file)]
manifest-file)
;; for hacking on 3rd-party drivers locally: set
;; `-Dmb.dev.additional.driver.manifest.paths=/path/to/whatever/metabase-plugin.yaml` or
;; `MB_DEV_ADDITIONAL_DRIVER_MANIFEST_PATHS=...` to have that plugin manifest get loaded during startup. Specify
;; multiple plugin manifests by comma-separating them.
(when-let [additional-paths (env/env :mb-dev-additional-driver-manifest-paths)]
(map files/get-path (str/split additional-paths #",")))))
(defn- load-local-plugin-manifests!
"Load local plugin manifest files when running in dev or test mode, to simulate what would happen when loading those
......
This diff is collapsed.
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