Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate kk payment daily person update jobs to different queue #1677

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"URL" payment-url "application-key" application-key)
(if mail-content
(let [job-id (jdbc/with-db-transaction [conn {:datasource (db/get-datasource :db)}]
(job/start-job job-runner conn job-type mail-content))]
(job/start-job job-runner conn job-type mail-content))]
(log/info "Created kk application payment" type-str "email job" job-id "for application" application-key))
(log/warn "Creating kk application payment" type-str "mail to application" application-key "failed"))))

Expand Down Expand Up @@ -171,37 +171,47 @@
[job-runner person-oid term year]
(when (get-in config [:kk-application-payments :enabled?])
(jdbc/with-db-transaction [conn {:datasource (db/get-datasource :db)}]
(job/start-job job-runner
conn
"kk-application-payment-person-status-update-job"
{:person_oid person-oid :term term :year year}))))
(job/start-job job-runner
conn
"kk-application-payment-person-status-update-job"
{:person_oid person-oid :term term :year year}))))

(defn start-update-kk-payment-status-for-application-key-job
[job-runner application-key]
(when (get-in config [:kk-application-payments :enabled?])
(jdbc/with-db-transaction [conn {:datasource (db/get-datasource :db)}]
(job/start-job job-runner
conn
"kk-application-payment-person-status-update-job"
{:application_key application-key}))))
(job/start-job job-runner
conn
"kk-application-payment-person-status-update-job"
{:application_key application-key}))))

(defn start-update-kk-payment-status-for-application-id-job
[job-runner application-id]
(when (get-in config [:kk-application-payments :enabled?])
(jdbc/with-db-transaction [conn {:datasource (db/get-datasource :db)}]
(job/start-job job-runner
conn
"kk-application-payment-person-status-update-job"
{:application_id application-id}))))
(job/start-job job-runner
conn
"kk-application-payment-person-status-update-job"
{:application_id application-id}))))

(defn start-update-kk-payment-status-for-all-job
[job-runner]
(when (get-in config [:kk-application-payments :enabled?])
(jdbc/with-db-transaction [conn {:datasource (db/get-datasource :db)}]
(job/start-job job-runner
conn
"kk-application-payment-status-update-scheduler-job"
{}))))
(job/start-job job-runner
conn
"kk-application-payment-status-update-scheduler-job"
{}))))

; Called only from the scheduler job.
(defn start-periodical-update-kk-payment-status-for-person-job
[job-runner person-oid term year]
(when (get-in config [:kk-application-payments :enabled?])
(jdbc/with-db-transaction [conn {:datasource (db/get-datasource :db)}]
(job/start-job job-runner
conn
"kk-application-payment-periodical-person-status-update-job"
{:person_oid person-oid :term term :year year}))))

; TODO: we might be updating status of a single person multiple times if they have applications in multiple hakus.
(defn update-statuses-for-haku
Expand All @@ -214,7 +224,7 @@
person-oids (distinct (application-store/get-application-person-oids-for-haku haku-oid))]
(log/info "Found" (count person-oids) "distinct oids for haku" haku-oid "- updating kk application payment statuses.")
(doseq [person-oid person-oids]
(start-update-kk-payment-status-for-person-job job-runner person-oid term year))))
(start-periodical-update-kk-payment-status-for-person-job job-runner person-oid term year))))

(defn get-hakus-and-update
"Finds active hakus that still need to have kk application payment statuses updated,
Expand All @@ -236,6 +246,12 @@
(def updater-job-definition {:handler update-kk-payment-status-for-person-handler
:type "kk-application-payment-person-status-update-job"})

; This uses the same handler as the person updater job, but is only called from the daily scheduler job.
; This way we get separate queues for the daily updates so that the person updater job is not blocked by
; the daily updates.
(def periodical-updater-job-definition {:handler update-kk-payment-status-for-person-handler
:type "kk-application-payment-periodical-person-status-update-job"})

(def scheduler-job-definition {:handler update-kk-payment-status-for-all-handler
:type "kk-application-payment-status-update-scheduler-job"
:schedule "0 6 * * *"})
2 changes: 2 additions & 0 deletions src/clj/ataru/virkailija/background_jobs/virkailija_jobs.clj
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
{:queue default-retry-strategy})
(:type kk-updater-job/updater-job-definition) (merge kk-updater-job/updater-job-definition
{:queue default-retry-strategy})
(:type kk-updater-job/periodical-updater-job-definition) (merge kk-updater-job/periodical-updater-job-definition
{:queue default-retry-strategy})
(:type kk-payment-module-job/job-definition) (merge kk-payment-module-job/job-definition
{:queue default-retry-strategy})
(:type kk-email-job/job-definition) (merge kk-email-job/job-definition
Expand Down
Loading