From 66624f3efceb9e1f42bf2f55ec0817c7c7c24d64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=A4in=C3=B6=20Ala-H=C3=A4rk=C3=B6nen?= Date: Fri, 10 Jan 2025 15:13:36 +0200 Subject: [PATCH 1/2] Separate kk payment daily person update jobs to different queue --- .vscode/settings.json | 3 ++ ...application_payment_status_updater_job.clj | 52 ++++++++++++------- .../background_jobs/virkailija_jobs.clj | 2 + 3 files changed, 39 insertions(+), 18 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000000..7b016a89fb --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "java.compile.nullAnalysis.mode": "automatic" +} \ No newline at end of file diff --git a/src/clj/ataru/kk_application_payment/kk_application_payment_status_updater_job.clj b/src/clj/ataru/kk_application_payment/kk_application_payment_status_updater_job.clj index 2bd3f3fb96..9f461d5e75 100644 --- a/src/clj/ataru/kk_application_payment/kk_application_payment_status_updater_job.clj +++ b/src/clj/ataru/kk_application_payment/kk_application_payment_status_updater_job.clj @@ -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")))) @@ -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 @@ -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, @@ -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 * * *"}) diff --git a/src/clj/ataru/virkailija/background_jobs/virkailija_jobs.clj b/src/clj/ataru/virkailija/background_jobs/virkailija_jobs.clj index b40e680c8d..82593dc9f2 100644 --- a/src/clj/ataru/virkailija/background_jobs/virkailija_jobs.clj +++ b/src/clj/ataru/virkailija/background_jobs/virkailija_jobs.clj @@ -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 From b544c77dbc7f8a4d076164ce67197713f390d2f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=A4in=C3=B6=20Ala-H=C3=A4rk=C3=B6nen?= Date: Fri, 10 Jan 2025 15:15:19 +0200 Subject: [PATCH 2/2] Remove accidentally committed file --- .vscode/settings.json | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 7b016a89fb..0000000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "java.compile.nullAnalysis.mode": "automatic" -} \ No newline at end of file