proletarian

emccue 2023-04-07T14:46:45.954789Z

Is there any way I can customize the executor? I'm adding sql logging but kinda want to turn it off for the proletariat worker's polling

emccue 2023-04-07T14:46:48.296199Z

(def ^:dynamic *log-sql*
  true)

(defn- logging-datasource
  "Wraps a datasource such that all queries that go through it are logged."
  [underlying-datasource]
  (let [logging-listener (doto (SLF4JQueryLoggingListener.)
                           (.setQueryLogEntryCreator
                             (DefaultQueryLogEntryCreator.))
                           (.setLoggingCondition
                             (reify LoggingCondition
                               (getAsBoolean [_]
                                 *log-sql*))))]
    (-> (ProxyDataSourceBuilder/create underlying-datasource)
        (.listener logging-listener)
        (.logQueryBySlf4j SLF4JLogLevel/INFO "lumanu.system.db")
        (.name "Query Logger")
        (.build))))

(defn start-db
  [{:keys [jdbcUrl]}]
  (logging-datasource
    (connection/->pool
      HikariDataSource
      {:jdbcUrl   jdbcUrl
       :classname "org.postgresql.Driver"})))

emccue 2023-04-07T14:47:04.018159Z

i was thinking I could bind a dynamic var but..

emccue 2023-04-07T14:50:17.769889Z

there is no convenient "get underlying" method on the proxy either, which stinks

emccue 2023-04-07T14:55:15.365139Z

nevermind!

(.unwrap ^DataSource db HikariDataSource)

👌 1