♻️ Port branching to the unified jobs substrate

develop replaced the legacy one-shot task system with app.jobs
(#11542). Two branching call sites still used the removed API, so the
backend no longer compiled on top of it:

- files-branch/delete-branch! schedules the branch file's
  :delete-object job with jobs/submit, joined to the caller's
  transaction through the cfg's ::db/conn, as files.clj does.
- files-pull-request/send-review-request-emails! queues the review
  request with eml/send and ::eml/reuse-conn, as the comment emails
  do, and now takes the transaction cfg instead of the connection.

The tests follow: the rollback test redefines eml/send, and the
file-gc scheduler test reads the scheduled work from the job table,
whose params are plain JSON.

AI-assisted-by: claude-opus-5-5
This commit is contained in:
Álvaro Tejero Cantero 2026-10-06 11:02:31 +02:00
parent d490639489
commit 9fae01b79b
No known key found for this signature in database
4 changed files with 21 additions and 18 deletions

View File

@ -34,6 +34,7 @@
[app.features.fdata :as fdata]
[app.features.file-snapshots :as fsnap]
[app.features.logical-deletion :as ldel]
[app.jobs :as jobs]
[app.loggers.audit :as-alias audit]
[app.loggers.webhooks :as-alias webhooks]
[app.msgbus :as mbus]
@ -49,7 +50,6 @@
[app.util.cache :as ucache]
[app.util.pointer-map :as pmap]
[app.util.services :as sv]
[app.worker :as wrk]
[clojure.set :as set]
[clojure.string :as str]))
@ -378,9 +378,9 @@
(close-branch-pull-requests! cfg id {:profile-id profile-id
:status "closed"
:deleted-at dt})
(wrk/submit! {::db/conn conn
::wrk/task :delete-object
::wrk/params {:object :file :deleted-at dt :id branch-file-id}})
(jobs/submit cfg
{::jobs/name :delete-object
::jobs/params {:object :file :deleted-at dt :id branch-file-id}})
{:topic branch-file-id
:message {:type :file-deleted
:file-id branch-file-id

View File

@ -212,7 +212,7 @@
"Notify `reviewers` (profile ids) that `actor-id` requested their review
on the pull request. Follows the same in-transaction outbox pattern as
the comment emails."
[conn {:keys [title description] :as pr} {:keys [team-id actor-id branch-name target-name reviewers]}]
[{:keys [::db/conn] :as cfg} {:keys [title description] :as pr} {:keys [team-id actor-id branch-name target-name reviewers]}]
(when (seq reviewers)
(let [users (->> (teams/get-users+props conn team-id)
(map profile/decode-row)
@ -222,8 +222,9 @@
url (format-pull-request-url pr team-id)]
(doseq [reviewer-id reviewers]
(when-let [{:keys [fullname email]} (get users reviewer-id)]
(eml/send!
{::eml/conn conn
(eml/send
cfg
{::eml/reuse-conn true
::eml/factory eml/review-request
:public-uri (cf/get :public-uri)
:to email
@ -349,7 +350,7 @@
:profile-id reviewer-id}
{::db/return-keys false}))
(send-review-request-emails! conn
(send-review-request-emails! cfg
{:id pr-id
:source-file-id branch-file-id
:title title
@ -596,7 +597,7 @@
cfg
msgbus
messages
(fn [{:keys [::db/conn]}]
(fn [{:keys [::db/conn] :as cfg}]
(db/update! conn :file-pull-request
(cond-> {:updated-at (ct/now)}
(some? title) (assoc :title title)
@ -621,7 +622,7 @@
:profile-id reviewer-id}))
(when (seq added)
(let [row (db/exec-one! conn [sql:get-pull-request id])]
(send-review-request-emails! conn row
(send-review-request-emails! cfg row
{:team-id team-id
:actor-id profile-id
:branch-name (:branch-name row)

View File

@ -48,14 +48,16 @@
(th/db-query :file-data {:file-id file-id :type "main"}))
(defn- scheduled-gc-file-ids
"The file ids of the `file-gc` tasks submitted so far."
"The file ids of the `file-gc` jobs submitted so far. A job's params
are plain JSON, so the id comes back as a string."
[]
(->> (th/db-query :task {:name "file-gc"})
(map (fn [{:keys [props]}]
(-> (if (db/pgobject? props)
(db/decode-transit-pgobject props)
props)
(get :file-id))))
(->> (th/db-query :job {:name "file-gc"})
(map (fn [{:keys [params]}]
(-> (if (db/pgobject? params)
(db/decode-json-pgobject params)
params)
(get :file-id)
(uuid/parse))))
(into #{})))
(defn- branch-row-id

View File

@ -854,7 +854,7 @@
;; that queueing fail after the pull request row is written
(with-redefs [mbus/pub! (fn [_ & {:keys [message]}]
(swap! seen conj message))
eml/send! (fn [_] (throw (IllegalStateException. "boom")))]
eml/send (fn [_ _] (throw (IllegalStateException. "boom")))]
(let [out (create-pr* author (:id branch) {:reviewers [(:id reviewer)]})]
(t/is (some? (:error out)))))
(t/is (empty? @seen))