mirror of
https://github.com/penpot/penpot.git
synced 2025-06-01 13:51:45 +02:00
✨ Fix linter issues on backend util namespace directory.
This commit is contained in:
parent
74077a0ead
commit
ce3c055819
14 changed files with 75 additions and 83 deletions
|
@ -6,9 +6,8 @@
|
||||||
|
|
||||||
(ns app.util.async
|
(ns app.util.async
|
||||||
(:require
|
(:require
|
||||||
[clojure.spec.alpha :as s]
|
[clojure.core.async :as a]
|
||||||
[clojure.tools.logging :as log]
|
[clojure.spec.alpha :as s])
|
||||||
[clojure.core.async :as a])
|
|
||||||
(:import
|
(:import
|
||||||
java.util.concurrent.Executor))
|
java.util.concurrent.Executor))
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
;; TODO: move to app.common.helpers
|
;; TODO: move to app.common.helpers
|
||||||
|
|
||||||
(defn dissoc-in
|
(defn dissoc-in
|
||||||
[m [k & ks :as keys]]
|
[m [k & ks]]
|
||||||
(if ks
|
(if ks
|
||||||
(if-let [nextmap (get m k)]
|
(if-let [nextmap (get m k)]
|
||||||
(let [newmap (dissoc-in nextmap ks)]
|
(let [newmap (dissoc-in nextmap ks)]
|
||||||
|
|
|
@ -8,14 +8,11 @@
|
||||||
"A generic service dispatcher implementation."
|
"A generic service dispatcher implementation."
|
||||||
(:refer-clojure :exclude [defmethod])
|
(:refer-clojure :exclude [defmethod])
|
||||||
(:require
|
(:require
|
||||||
[clojure.spec.alpha :as s]
|
[app.common.exceptions :as ex]
|
||||||
[expound.alpha :as expound]
|
[clojure.spec.alpha :as s])
|
||||||
[app.common.exceptions :as ex])
|
|
||||||
(:import
|
(:import
|
||||||
clojure.lang.IDeref
|
java.util.HashMap
|
||||||
clojure.lang.MapEntry
|
java.util.Map))
|
||||||
java.util.Map
|
|
||||||
java.util.HashMap))
|
|
||||||
|
|
||||||
(definterface IDispatcher
|
(definterface IDispatcher
|
||||||
(^void add [key f]))
|
(^void add [key f]))
|
||||||
|
|
|
@ -5,27 +5,25 @@
|
||||||
;; This Source Code Form is "Incompatible With Secondary Licenses", as
|
;; This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||||
;; defined by the Mozilla Public License, v. 2.0.
|
;; defined by the Mozilla Public License, v. 2.0.
|
||||||
;;
|
;;
|
||||||
;; Copyright (c) 2019-2020 Andrey Antukh <niwi@niwi.nz>
|
;; Copyright (c) 2020 UXBOX Labs SL
|
||||||
|
|
||||||
(ns app.util.emails
|
(ns app.util.emails
|
||||||
(:require
|
(:require
|
||||||
|
[app.common.exceptions :as ex]
|
||||||
|
[app.common.spec :as us]
|
||||||
|
[app.util.template :as tmpl]
|
||||||
[clojure.java.io :as io]
|
[clojure.java.io :as io]
|
||||||
[clojure.spec.alpha :as s]
|
[clojure.spec.alpha :as s]
|
||||||
[cuerdas.core :as str]
|
[cuerdas.core :as str])
|
||||||
[app.common.spec :as us]
|
|
||||||
[app.common.exceptions :as ex]
|
|
||||||
[app.util.template :as tmpl])
|
|
||||||
(:import
|
(:import
|
||||||
java.util.Properties
|
java.util.Properties
|
||||||
javax.mail.Message
|
|
||||||
javax.mail.Transport
|
|
||||||
javax.mail.Message$RecipientType
|
javax.mail.Message$RecipientType
|
||||||
javax.mail.PasswordAuthentication
|
|
||||||
javax.mail.Session
|
javax.mail.Session
|
||||||
|
javax.mail.Transport
|
||||||
javax.mail.internet.InternetAddress
|
javax.mail.internet.InternetAddress
|
||||||
javax.mail.internet.MimeMultipart
|
|
||||||
javax.mail.internet.MimeBodyPart
|
javax.mail.internet.MimeBodyPart
|
||||||
javax.mail.internet.MimeMessage))
|
javax.mail.internet.MimeMessage
|
||||||
|
javax.mail.internet.MimeMultipart))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; Email Building
|
;; Email Building
|
||||||
|
@ -205,8 +203,7 @@
|
||||||
|
|
||||||
(defn- build-email-template
|
(defn- build-email-template
|
||||||
[id context]
|
[id context]
|
||||||
(let [lang (:lang context :en)
|
(let [subj (render-email-template-part :subj id context)
|
||||||
subj (render-email-template-part :subj id context)
|
|
||||||
text (render-email-template-part :txt id context)
|
text (render-email-template-part :txt id context)
|
||||||
html (render-email-template-part :html id context)]
|
html (render-email-template-part :html id context)]
|
||||||
(when (or (not subj)
|
(when (or (not subj)
|
||||||
|
|
|
@ -2,14 +2,16 @@
|
||||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
;;
|
;;
|
||||||
;; Copyright (c) 2019 Andrey Antukh <niwi@niwi.nz>
|
;; This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||||
|
;; defined by the Mozilla Public License, v. 2.0.
|
||||||
|
;;
|
||||||
|
;; Copyright (c) 2020 UXBOX Labs SL
|
||||||
|
|
||||||
(ns app.util.http
|
(ns app.util.http
|
||||||
"Http client abstraction layer."
|
"Http client abstraction layer."
|
||||||
(:require
|
(:require
|
||||||
[promesa.core :as p]
|
[java-http-clj.core :as http]
|
||||||
[promesa.exec :as px]
|
[promesa.exec :as px]))
|
||||||
[java-http-clj.core :as http]))
|
|
||||||
|
|
||||||
(def default-client
|
(def default-client
|
||||||
(delay (http/build-client {:executor @px/default-executor})))
|
(delay (http/build-client {:executor @px/default-executor})))
|
||||||
|
|
|
@ -2,13 +2,16 @@
|
||||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
;;
|
;;
|
||||||
;; Copyright (c) 2019 Andrey Antukh <niwi@niwi.nz>
|
;; This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||||
|
;; defined by the Mozilla Public License, v. 2.0.
|
||||||
|
;;
|
||||||
|
;; Copyright (c) 2020 UXBOX Labs SL
|
||||||
|
|
||||||
(ns app.util.migrations
|
(ns app.util.migrations
|
||||||
(:require
|
(:require
|
||||||
[clojure.tools.logging :as log]
|
|
||||||
[clojure.java.io :as io]
|
[clojure.java.io :as io]
|
||||||
[clojure.spec.alpha :as s]
|
[clojure.spec.alpha :as s]
|
||||||
|
[clojure.tools.logging :as log]
|
||||||
[cuerdas.core :as str]
|
[cuerdas.core :as str]
|
||||||
[next.jdbc :as jdbc]))
|
[next.jdbc :as jdbc]))
|
||||||
|
|
||||||
|
@ -45,7 +48,7 @@
|
||||||
((:fn migration) pool))))
|
((:fn migration) pool))))
|
||||||
|
|
||||||
(defn- impl-migrate
|
(defn- impl-migrate
|
||||||
[conn migrations {:keys [fake] :or {fake false}}]
|
[conn migrations _opts]
|
||||||
(s/assert ::migrations migrations)
|
(s/assert ::migrations migrations)
|
||||||
(let [mname (:name migrations)
|
(let [mname (:name migrations)
|
||||||
steps (:steps migrations)]
|
steps (:steps migrations)]
|
||||||
|
|
|
@ -2,14 +2,17 @@
|
||||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
;;
|
;;
|
||||||
;; Copyright (c) 2019 Andrey Antukh <niwi@niwi.nz>
|
;; This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||||
|
;; defined by the Mozilla Public License, v. 2.0.
|
||||||
|
;;
|
||||||
|
;; Copyright (c) 2020 UXBOX Labs SL
|
||||||
|
|
||||||
(ns app.util.redis
|
(ns app.util.redis
|
||||||
"Asynchronous posgresql client."
|
"Asynchronous posgresql client."
|
||||||
(:refer-clojure :exclude [run!])
|
(:refer-clojure :exclude [run!])
|
||||||
(:require
|
(:require
|
||||||
[promesa.core :as p]
|
[clojure.core.async :as a]
|
||||||
[clojure.core.async :as a])
|
[promesa.core :as p])
|
||||||
(:import
|
(:import
|
||||||
io.lettuce.core.RedisClient
|
io.lettuce.core.RedisClient
|
||||||
io.lettuce.core.RedisURI
|
io.lettuce.core.RedisURI
|
||||||
|
@ -18,7 +21,6 @@
|
||||||
io.lettuce.core.api.StatefulRedisConnection
|
io.lettuce.core.api.StatefulRedisConnection
|
||||||
io.lettuce.core.pubsub.RedisPubSubListener
|
io.lettuce.core.pubsub.RedisPubSubListener
|
||||||
io.lettuce.core.pubsub.StatefulRedisPubSubConnection
|
io.lettuce.core.pubsub.StatefulRedisPubSubConnection
|
||||||
io.lettuce.core.pubsub.api.async.RedisPubSubAsyncCommands
|
|
||||||
io.lettuce.core.pubsub.api.sync.RedisPubSubCommands
|
io.lettuce.core.pubsub.api.sync.RedisPubSubCommands
|
||||||
))
|
))
|
||||||
|
|
||||||
|
@ -87,7 +89,7 @@
|
||||||
output))
|
output))
|
||||||
|
|
||||||
(defn subscribe
|
(defn subscribe
|
||||||
[{:keys [uri] :as client} {:keys [topic topics xform]}]
|
[{:keys [uri] :as client} {:keys [topics xform]}]
|
||||||
(let [topics (if (vector? topics)
|
(let [topics (if (vector? topics)
|
||||||
(into-array String (map str topics))
|
(into-array String (map str topics))
|
||||||
(into-array String [(str topics)]))]
|
(into-array String [(str topics)]))]
|
||||||
|
@ -100,7 +102,7 @@
|
||||||
true
|
true
|
||||||
false))
|
false))
|
||||||
|
|
||||||
(defmulti impl-run (fn [conn cmd parmas] cmd))
|
(defmulti impl-run (fn [_ cmd _] cmd))
|
||||||
|
|
||||||
(defn run!
|
(defn run!
|
||||||
[conn cmd params]
|
[conn cmd params]
|
||||||
|
|
|
@ -164,7 +164,7 @@
|
||||||
(defn- process-param-tokens
|
(defn- process-param-tokens
|
||||||
[sql]
|
[sql]
|
||||||
(let [cnt (java.util.concurrent.atomic.AtomicInteger. 1)]
|
(let [cnt (java.util.concurrent.atomic.AtomicInteger. 1)]
|
||||||
(str/replace sql #"\?" (fn [& args]
|
(str/replace sql #"\?" (fn [& _args]
|
||||||
(str "$" (.getAndIncrement cnt))))))
|
(str "$" (.getAndIncrement cnt))))))
|
||||||
|
|
||||||
(def ^:private select-formatters
|
(def ^:private select-formatters
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
;; This Source Code Form is "Incompatible With Secondary Licenses", as
|
;; This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||||
;; defined by the Mozilla Public License, v. 2.0.
|
;; defined by the Mozilla Public License, v. 2.0.
|
||||||
;;
|
;;
|
||||||
;; Copyright (c) 2020 Andrey Antukh <niwi@niwi.nz>
|
;; Copyright (c) 2020 UXBOX Labs SL
|
||||||
|
|
||||||
(ns app.util.storage
|
(ns app.util.storage
|
||||||
"A local filesystem storage implementation."
|
"A local filesystem storage implementation."
|
||||||
|
@ -16,17 +16,14 @@
|
||||||
[clojure.java.io :as io]
|
[clojure.java.io :as io]
|
||||||
[clojure.spec.alpha :as s]
|
[clojure.spec.alpha :as s]
|
||||||
[cuerdas.core :as str]
|
[cuerdas.core :as str]
|
||||||
[datoteka.core :as fs]
|
[datoteka.core :as fs])
|
||||||
[datoteka.proto :as fp])
|
|
||||||
(:import
|
(:import
|
||||||
java.io.ByteArrayInputStream
|
java.io.ByteArrayInputStream
|
||||||
java.io.InputStream
|
java.io.InputStream
|
||||||
java.io.OutputStream
|
java.io.OutputStream
|
||||||
java.net.URI
|
java.net.URI
|
||||||
java.nio.file.Files
|
|
||||||
java.nio.file.NoSuchFileException
|
java.nio.file.NoSuchFileException
|
||||||
java.nio.file.Path
|
java.nio.file.Path))
|
||||||
java.security.MessageDigest))
|
|
||||||
|
|
||||||
(defn uri
|
(defn uri
|
||||||
[v]
|
[v]
|
||||||
|
@ -54,7 +51,7 @@
|
||||||
(defn- transform-path
|
(defn- transform-path
|
||||||
[storage ^Path path]
|
[storage ^Path path]
|
||||||
(if-let [xf (::xf storage)]
|
(if-let [xf (::xf storage)]
|
||||||
((xf (fn [a b] b)) nil path)
|
((xf (fn [_ b] b)) nil path)
|
||||||
path))
|
path))
|
||||||
|
|
||||||
(defn blob
|
(defn blob
|
||||||
|
@ -89,7 +86,7 @@
|
||||||
(normalize-path (::base-path storage))
|
(normalize-path (::base-path storage))
|
||||||
(fs/delete))
|
(fs/delete))
|
||||||
true
|
true
|
||||||
(catch java.nio.file.NoSuchFileException e
|
(catch NoSuchFileException _e
|
||||||
false)))
|
false)))
|
||||||
|
|
||||||
(defn clear!
|
(defn clear!
|
||||||
|
|
|
@ -2,21 +2,23 @@
|
||||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
;;
|
;;
|
||||||
;; Copyright (c) 2016-2019 Andrey Antukh <niwi@niwi.nz>
|
;; This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||||
|
;; defined by the Mozilla Public License, v. 2.0.
|
||||||
|
;;
|
||||||
|
;; Copyright (c) 2020 UXBOX Labs SL
|
||||||
|
|
||||||
(ns app.util.svg
|
(ns app.util.svg
|
||||||
"Icons SVG parsing helpers."
|
"Icons SVG parsing helpers."
|
||||||
(:require
|
(:require
|
||||||
[clojure.spec.alpha :as s]
|
[app.common.exceptions :as ex]
|
||||||
[cuerdas.core :as str]
|
|
||||||
[app.common.spec :as us]
|
[app.common.spec :as us]
|
||||||
[app.common.exceptions :as ex])
|
[clojure.spec.alpha :as s]
|
||||||
|
[cuerdas.core :as str])
|
||||||
(:import
|
(:import
|
||||||
org.jsoup.Jsoup
|
org.jsoup.Jsoup
|
||||||
org.jsoup.nodes.Attribute
|
org.jsoup.nodes.Attribute
|
||||||
org.jsoup.nodes.Element
|
org.jsoup.nodes.Element
|
||||||
org.jsoup.nodes.Document
|
org.jsoup.nodes.Document))
|
||||||
java.io.InputStream))
|
|
||||||
|
|
||||||
(s/def ::content string?)
|
(s/def ::content string?)
|
||||||
(s/def ::width ::us/number)
|
(s/def ::width ::us/number)
|
||||||
|
@ -65,19 +67,19 @@
|
||||||
content (.html element)
|
content (.html element)
|
||||||
attrs (parse-attrs element)]
|
attrs (parse-attrs element)]
|
||||||
(assoc attrs :content content))
|
(assoc attrs :content content))
|
||||||
(catch java.lang.IllegalArgumentException e
|
(catch java.lang.IllegalArgumentException _e
|
||||||
(ex/raise :type :validation
|
(ex/raise :type :validation
|
||||||
:code ::invalid-input
|
:code ::invalid-input
|
||||||
:message "Input does not seems to be a valid svg."))
|
:message "Input does not seems to be a valid svg."))
|
||||||
(catch java.lang.NullPointerException e
|
(catch java.lang.NullPointerException _e
|
||||||
(ex/raise :type :validation
|
(ex/raise :type :validation
|
||||||
:code ::invalid-input
|
:code ::invalid-input
|
||||||
:message "Input does not seems to be a valid svg."))
|
:message "Input does not seems to be a valid svg."))
|
||||||
(catch org.jsoup.UncheckedIOException e
|
(catch org.jsoup.UncheckedIOException _e
|
||||||
(ex/raise :type :validation
|
(ex/raise :type :validation
|
||||||
:code ::invalid-input
|
:code ::invalid-input
|
||||||
:message "Input does not seems to be a valid svg."))
|
:message "Input does not seems to be a valid svg."))
|
||||||
(catch Exception e
|
(catch Exception _e
|
||||||
(ex/raise :type :internal
|
(ex/raise :type :internal
|
||||||
:code ::unexpected))))
|
:code ::unexpected))))
|
||||||
|
|
||||||
|
|
|
@ -2,18 +2,17 @@
|
||||||
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
;;
|
;;
|
||||||
;; Copyright (c) 2016-2019 Andrey Antukh <niwi@niwi.nz>
|
;; This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||||
|
;; defined by the Mozilla Public License, v. 2.0.
|
||||||
|
;;
|
||||||
|
;; Copyright (c) 2020 UXBOX Labs SL
|
||||||
|
|
||||||
(ns app.util.template
|
(ns app.util.template
|
||||||
"A lightweight abstraction over mustache.java template engine.
|
"A lightweight abstraction over mustache.java template engine.
|
||||||
The documentation can be found: http://mustache.github.io/mustache.5.html"
|
The documentation can be found: http://mustache.github.io/mustache.5.html"
|
||||||
(:require
|
(:require
|
||||||
[clojure.tools.logging :as log]
|
[app.common.exceptions :as ex]
|
||||||
[clojure.walk :as walk]
|
[selmer.parser :as sp]))
|
||||||
[clojure.java.io :as io]
|
|
||||||
[cuerdas.core :as str]
|
|
||||||
[selmer.parser :as sp]
|
|
||||||
[app.common.exceptions :as ex]))
|
|
||||||
|
|
||||||
;; (sp/cache-off!)
|
;; (sp/cache-off!)
|
||||||
|
|
||||||
|
|
|
@ -5,12 +5,12 @@
|
||||||
;; This Source Code Form is "Incompatible With Secondary Licenses", as
|
;; This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||||
;; defined by the Mozilla Public License, v. 2.0.
|
;; defined by the Mozilla Public License, v. 2.0.
|
||||||
;;
|
;;
|
||||||
;; Copyright (c) 2016-2020 Andrey Antukh <niwi@niwi.nz>
|
;; Copyright (c) 2020 UXBOX Labs SL
|
||||||
|
|
||||||
(ns app.util.time
|
(ns app.util.time
|
||||||
(:require
|
(:require
|
||||||
[clojure.spec.alpha :as s]
|
|
||||||
[app.common.exceptions :as ex]
|
[app.common.exceptions :as ex]
|
||||||
|
[clojure.spec.alpha :as s]
|
||||||
[cognitect.transit :as t])
|
[cognitect.transit :as t])
|
||||||
(:import
|
(:import
|
||||||
java.time.Instant
|
java.time.Instant
|
||||||
|
@ -106,7 +106,7 @@
|
||||||
(string? v)
|
(string? v)
|
||||||
(try
|
(try
|
||||||
(parse-duration v)
|
(parse-duration v)
|
||||||
(catch java.time.format.DateTimeParseException e
|
(catch java.time.format.DateTimeParseException _e
|
||||||
::s/invalid))
|
::s/invalid))
|
||||||
|
|
||||||
:else
|
:else
|
||||||
|
|
|
@ -9,13 +9,11 @@
|
||||||
|
|
||||||
(ns app.util.transit
|
(ns app.util.transit
|
||||||
(:require
|
(:require
|
||||||
[cognitect.transit :as t]
|
[app.common.geom.matrix :as gmt]
|
||||||
[clojure.java.io :as io]
|
|
||||||
[linked.core :as lk]
|
|
||||||
[app.util.time :as dt]
|
|
||||||
[app.util.data :as data]
|
|
||||||
[app.common.geom.point :as gpt]
|
[app.common.geom.point :as gpt]
|
||||||
[app.common.geom.matrix :as gmt])
|
[app.util.time :as dt]
|
||||||
|
[cognitect.transit :as t]
|
||||||
|
[linked.core :as lk])
|
||||||
(:import
|
(:import
|
||||||
linked.set.LinkedSet
|
linked.set.LinkedSet
|
||||||
java.io.ByteArrayInputStream
|
java.io.ByteArrayInputStream
|
||||||
|
|
|
@ -15,12 +15,11 @@
|
||||||
[app.db :as db]
|
[app.db :as db]
|
||||||
[app.tasks.delete-object]
|
[app.tasks.delete-object]
|
||||||
[app.tasks.delete-profile]
|
[app.tasks.delete-profile]
|
||||||
[app.tasks.remove-media]
|
|
||||||
[app.tasks.maintenance]
|
[app.tasks.maintenance]
|
||||||
|
[app.tasks.remove-media]
|
||||||
[app.tasks.sendmail]
|
[app.tasks.sendmail]
|
||||||
[app.tasks.trim-file]
|
[app.tasks.trim-file]
|
||||||
[app.util.async :as aa]
|
[app.util.async :as aa]
|
||||||
[app.util.blob :as blob]
|
|
||||||
[app.util.time :as dt]
|
[app.util.time :as dt]
|
||||||
[clojure.core.async :as a]
|
[clojure.core.async :as a]
|
||||||
[clojure.spec.alpha :as s]
|
[clojure.spec.alpha :as s]
|
||||||
|
@ -31,10 +30,7 @@
|
||||||
org.eclipse.jetty.util.thread.QueuedThreadPool
|
org.eclipse.jetty.util.thread.QueuedThreadPool
|
||||||
java.util.concurrent.ExecutorService
|
java.util.concurrent.ExecutorService
|
||||||
java.util.concurrent.Executors
|
java.util.concurrent.Executors
|
||||||
java.util.concurrent.Executor
|
java.time.Instant))
|
||||||
java.time.Duration
|
|
||||||
java.time.Instant
|
|
||||||
java.util.Date))
|
|
||||||
|
|
||||||
(declare start-scheduler-worker!)
|
(declare start-scheduler-worker!)
|
||||||
(declare start-worker!)
|
(declare start-worker!)
|
||||||
|
@ -149,7 +145,7 @@
|
||||||
nil))))
|
nil))))
|
||||||
|
|
||||||
(defn- run-task
|
(defn- run-task
|
||||||
[{:keys [tasks conn]} item]
|
[{:keys [tasks]} item]
|
||||||
(try
|
(try
|
||||||
(log/debugf "Started task '%s/%s/%s'." (:name item) (:id item) (:retry-num item))
|
(log/debugf "Started task '%s/%s/%s'." (:name item) (:id item) (:retry-num item))
|
||||||
(handle-task tasks item)
|
(handle-task tasks item)
|
||||||
|
@ -187,7 +183,7 @@
|
||||||
for update skip locked")
|
for update skip locked")
|
||||||
|
|
||||||
(defn- event-loop-fn*
|
(defn- event-loop-fn*
|
||||||
[{:keys [tasks executor batch-size] :as opts}]
|
[{:keys [executor batch-size] :as opts}]
|
||||||
(db/with-atomic [conn db/pool]
|
(db/with-atomic [conn db/pool]
|
||||||
(let [queue (:queue opts "default")
|
(let [queue (:queue opts "default")
|
||||||
items (->> (db/exec! conn [sql:select-next-tasks queue batch-size])
|
items (->> (db/exec! conn [sql:select-next-tasks queue batch-size])
|
||||||
|
@ -222,7 +218,7 @@
|
||||||
:opt-un [::poll-interval]))
|
:opt-un [::poll-interval]))
|
||||||
|
|
||||||
(defn start-worker!
|
(defn start-worker!
|
||||||
[{:keys [poll-interval executor]
|
[{:keys [poll-interval]
|
||||||
:or {poll-interval 5000}
|
:or {poll-interval 5000}
|
||||||
:as opts}]
|
:as opts}]
|
||||||
(us/assert ::start-worker-params opts)
|
(us/assert ::start-worker-params opts)
|
||||||
|
@ -290,7 +286,7 @@
|
||||||
do update set cron_expr=?")
|
do update set cron_expr=?")
|
||||||
|
|
||||||
(defn- synchronize-schedule-item
|
(defn- synchronize-schedule-item
|
||||||
[conn {:keys [id cron] :as item}]
|
[conn {:keys [id cron]}]
|
||||||
(let [cron (str cron)]
|
(let [cron (str cron)]
|
||||||
(log/debugf "Initialize scheduled task '%s' (cron: '%s')." id cron)
|
(log/debugf "Initialize scheduled task '%s' (cron: '%s')." id cron)
|
||||||
(db/exec-one! conn [sql:upsert-scheduled-task id cron cron])))
|
(db/exec-one! conn [sql:upsert-scheduled-task id cron cron])))
|
||||||
|
@ -311,7 +307,7 @@
|
||||||
(.printStackTrace ^Throwable error (java.io.PrintWriter. *out*))))
|
(.printStackTrace ^Throwable error (java.io.PrintWriter. *out*))))
|
||||||
|
|
||||||
(defn- execute-scheduled-task
|
(defn- execute-scheduled-task
|
||||||
[{:keys [scheduler executor] :as opts} {:keys [id cron] :as task}]
|
[{:keys [executor] :as opts} {:keys [id] :as task}]
|
||||||
(letfn [(run-task [conn]
|
(letfn [(run-task [conn]
|
||||||
(try
|
(try
|
||||||
(when (db/exec-one! conn [sql:lock-scheduled-task id])
|
(when (db/exec-one! conn [sql:lock-scheduled-task id])
|
||||||
|
@ -384,7 +380,7 @@
|
||||||
|
|
||||||
(defn thread-pool
|
(defn thread-pool
|
||||||
([] (thread-pool {}))
|
([] (thread-pool {}))
|
||||||
([{:keys [min-threads max-threads idle-timeout name]
|
([{:keys [min-threads max-threads name]
|
||||||
:or {min-threads 0 max-threads 128 idle-timeout 60000}}]
|
:or {min-threads 0 max-threads 128 idle-timeout 60000}}]
|
||||||
(let [executor (QueuedThreadPool. max-threads min-threads)]
|
(let [executor (QueuedThreadPool. max-threads min-threads)]
|
||||||
(.setName executor (or name "default-tp"))
|
(.setName executor (or name "default-tp"))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue