0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-07 15:39:42 -05:00

Use schema instead of spec for validate worker submit options

This commit is contained in:
Andrey Antukh 2024-10-29 19:33:42 +01:00 committed by Alonso Torres
parent 32126d1874
commit a9d3dfab1a

View file

@ -10,6 +10,7 @@
[app.common.data :as d] [app.common.data :as d]
[app.common.data.macros :as dm] [app.common.data.macros :as dm]
[app.common.logging :as l] [app.common.logging :as l]
[app.common.schema :as sm]
[app.common.spec :as us] [app.common.spec :as us]
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
[app.config :as cf] [app.config :as cf]
@ -73,29 +74,27 @@
AND status = 'new' AND status = 'new'
AND scheduled_at > now()") AND scheduled_at > now()")
(s/def ::label string?) (def ^:private schema:options
(s/def ::task (s/or :kw keyword? :str string?)) [:map {:title "submit-options"}
(s/def ::queue (s/or :kw keyword? :str string?)) [::task [:or ::sm/text :keyword]]
(s/def ::delay (s/or :int integer? :duration dt/duration?)) [::label {:optional true} ::sm/text]
(s/def ::priority integer?) [::delay {:optional true}
(s/def ::max-retries integer?) [:or ::sm/int ::dt/duration]]
(s/def ::dedupe boolean?) [::queue {:optional true} [:or ::sm/text :keyword]]
[::priority {:optional true} ::sm/int]
[::max-retries {:optional true} ::sm/int]
[::dedupe {:optional true} ::sm/boolean]])
(s/def ::submit-options (def check-options!
(s/and (sm/check-fn schema:options))
(s/keys :req [::task]
:opt [::label ::delay ::queue ::priority ::max-retries ::dedupe])
(fn [{:keys [::dedupe ::label] :or {label ""}}]
(if dedupe
(not= label "")
true))))
(defn submit! (defn submit!
[& {:keys [::params ::task ::delay ::queue ::priority ::max-retries ::dedupe ::label] [& {:keys [::params ::task ::delay ::queue ::priority ::max-retries ::dedupe ::label]
:or {delay 0 queue :default priority 100 max-retries 3 label ""} :or {delay 0 queue :default priority 100 max-retries 3 label ""}
:as options}] :as options}]
(us/verify! ::submit-options options) (check-options! options)
(let [duration (dt/duration delay) (let [duration (dt/duration delay)
interval (db/interval duration) interval (db/interval duration)
props (db/tjson params) props (db/tjson params)