This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-08-18
Channels
- # announcements (22)
- # asami (7)
- # babashka (43)
- # beginners (68)
- # biff (2)
- # calva (10)
- # clj-kondo (7)
- # cljdoc (29)
- # clojure (41)
- # clojure-austin (1)
- # clojure-brasil (2)
- # clojure-europe (25)
- # clojure-gamedev (3)
- # clojure-nl (2)
- # clojure-norway (9)
- # clojure-uk (31)
- # clojurescript (3)
- # community-development (7)
- # cursive (3)
- # data-science (4)
- # datomic (17)
- # emacs (30)
- # honeysql (10)
- # hyperfiddle (39)
- # introduce-yourself (1)
- # jobs-discuss (5)
- # kaocha (1)
- # lsp (11)
- # malli (12)
- # pathom (18)
- # pedestal (3)
- # proletarian (2)
- # quil (11)
- # rdf (46)
- # reitit (8)
- # releases (2)
- # shadow-cljs (34)
- # sql (3)
- # squint (10)
- # tools-deps (24)
- # xtdb (10)
hey, this is an awesome tool and i love how it “just works”. kudos to the creators/maintainers. data-driven and simple, it feels as clojure-ey as you could ask of any lib.
2
i ran into something the other day that confused me, a little, but i haven’t yet found the time to dig into the issue. for now i found a different way to invoke the library that avoids this issue… but i’m going to leave this as a note for anyone else in the future who might get equally confused: the normal worker creation looks something like this:
(let [ds (jdbc/get-datasource db/pgres)]
(worker/create-queue-worker ds handle-job! #:proletarian{:log logger
:worker-threads 1
:retry-strategy-fn retry-job!
:failed-job-fn failed-job!
:install-jvm-shutdown-hook? true}))
i have structured my codebase so that individual modules that need to generate a worker can provide their own retry-job and failed-job functions. the wrong way to do it (i think), is to provide function refs from the module.
... ns my.app.has-work-to-do
(my.app.workers/create-worker my.app.has-work-to-do/retry-job! my-app.has-work-to-do/failed-job!)
... ns my.app.has-more-work-to-do
(my.app.workers/create-worker my.app.has-more-work-to-do/retry-job! my-app.has-more-work-to-do/failed-job!)
... ns my.app.workers
(defn create-worker [retry-job! failed-job!]
(let [ds (jdbc/get-datasource db/pgres)]
(worker/create-queue-worker ds handle-job! #:proletarian{:log logger
:worker-threads 1
:retry-strategy-fn retry-job!
:failed-job-fn failed-job!
:install-jvm-shutdown-hook? true})))
what i noticed when running workers is that failed jobs in my.app.has-work-to-do could actually invoke the my.app.has-more-work-to-do/failed-job
handler. after a few hours of exploration i couldn’t really figure out why. it might be a conceptual misunderstanding of the documentation + library’s intent. this could also potentially be due to some bad state in my system layout (i am using mount, for example). but… you can sidestep this issue entirely via multimethods for the retry-job and failed-job handlers.
... ns my.app.workers
(defmulti retry-job! (fn [job-type _payload] job-type))
... ns my.app.has-work-to-do
(defmethod retry-job! ::has-work-to-do [type payload] ...)
... ns my.app.has-more-work-to-do
(defmethod retry-job! ::has-more-work-to-do [type payload] ...)
this seems entirely more sensible considering multimethods are also the recommended way to dispatch on the workers’ handle-job!.