mirror of
https://github.com/penpot/penpot.git
synced 2025-04-14 16:01:24 -05:00
✨ Minor changes on tasks subsystem.
This commit is contained in:
parent
f2cb2c3791
commit
8061ee7ca7
3 changed files with 12 additions and 13 deletions
|
@ -51,7 +51,7 @@
|
|||
[{:id "every 1 hour"
|
||||
:cron #uxbox/cron "1 1 */1 * * ? *"
|
||||
:fn #'uxbox.tasks.demo-gc/handler
|
||||
:props {:foo "bar"}}])
|
||||
:props {:foo 1}}])
|
||||
|
||||
(defstate scheduler
|
||||
:start (as-> (impl/scheduler-verticle {:schedule schedule}) $$
|
||||
|
|
|
@ -16,5 +16,8 @@
|
|||
(defn handler
|
||||
{:uxbox.tasks/name "demo-gc"}
|
||||
[{:keys [props] :as task}]
|
||||
(Thread/sleep 500)
|
||||
(prn (.getName (Thread/currentThread)) "demo-gc" (:id task) (:props task)))
|
||||
(try
|
||||
(Thread/sleep 100)
|
||||
(prn (.getName (Thread/currentThread)) "demo-gc" (:id task) (:props task))
|
||||
(catch Throwable e
|
||||
nil)))
|
||||
|
|
|
@ -180,14 +180,11 @@
|
|||
(db/with-atomic [conn db/pool]
|
||||
(-> (db/query-one conn [sql:lock-scheduled-task id])
|
||||
(p/then (fn [result]
|
||||
(if result
|
||||
(do
|
||||
(prn (thr-name) "execute-scheduled-task" "task-locked")
|
||||
(-> (p/do! ((:fn stask) stask))
|
||||
(p/catch (fn [e]
|
||||
(log/warn "Excepton happens on executing scheduled task" e)
|
||||
nil))))
|
||||
(prn (thr-name) "execute-scheduled-task" "task-already-locked"))))
|
||||
(when result
|
||||
(-> (p/do! ((:fn stask) stask))
|
||||
(p/catch (fn [e]
|
||||
(log/warn "Excepton happens on executing scheduled task" e)
|
||||
nil))))))
|
||||
(p/finally (fn [v e]
|
||||
(-> (vc/current-context)
|
||||
(schedule-task stask)))))))
|
||||
|
@ -196,14 +193,13 @@
|
|||
[cron]
|
||||
(s/assert tm/cron? cron)
|
||||
(let [^Instant now (tm/now)
|
||||
^Instant next (.toInstant (.getNextValidTimeAfter cron (Date/from now)))
|
||||
^Instant next (tm/next-valid-instant-from cron now)
|
||||
^Duration duration (Duration/between now next)]
|
||||
(.toMillis duration)))
|
||||
|
||||
(defn- schedule-task
|
||||
[ctx {:keys [cron] :as stask}]
|
||||
(let [ms (ms-until-valid cron)]
|
||||
(prn (thr-name) "schedule-task" (:id stask) ms)
|
||||
(vt/schedule! ctx (assoc stask
|
||||
:ctx ctx
|
||||
::vt/once true
|
||||
|
|
Loading…
Add table
Reference in a new issue