From feb88432a999157a26718319c6bd01cf0b75f3ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phan=20Mestach?= Date: Mon, 23 Sep 2024 19:44:04 +0200 Subject: [PATCH] ttl for worker --- app/workers/dhis2_snapshot_worker.rb | 2 +- app/workers/invoice_for_project_anchor_worker.rb | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/app/workers/dhis2_snapshot_worker.rb b/app/workers/dhis2_snapshot_worker.rb index 4114efb2..7b08cdbb 100644 --- a/app/workers/dhis2_snapshot_worker.rb +++ b/app/workers/dhis2_snapshot_worker.rb @@ -8,7 +8,7 @@ class Dhis2SnapshotWorker PAGE_SIZE = 1000 sidekiq_throttle( - concurrency: { limit: 1 }, + concurrency: { limit: 1, ttl: ENV.fetch("SDKQ_MAX_TTL_SNAPSHOT", 1.hour.to_i.to_s).to_i }, threshold: { limit: 3, period: 2.minutes } ) diff --git a/app/workers/invoice_for_project_anchor_worker.rb b/app/workers/invoice_for_project_anchor_worker.rb index 2b338603..f8c01653 100644 --- a/app/workers/invoice_for_project_anchor_worker.rb +++ b/app/workers/invoice_for_project_anchor_worker.rb @@ -9,7 +9,10 @@ class InvoiceForProjectAnchorWorker ) sidekiq_throttle( - concurrency: { limit: ENV.fetch("SDKQ_MAX_CONCURRENT_INVOICE", 3).to_i }, + concurrency: { + limit: ENV.fetch("SDKQ_MAX_CONCURRENT_INVOICE", 3).to_i, + ttl: ENV.fetch("SDKQ_MAX_TTL_INVOICE", 1.hour.to_i.to_s).to_i + }, key_suffix: ->(project_anchor_id, _year, _quarter, _selected_org_unit_ids = nil, _options = {}) { per_process_id = ENV.fetch("HEROKU_DYNO_ID", $PROCESS_ID) [project_anchor_id, per_process_id].join("-") @@ -17,6 +20,16 @@ class InvoiceForProjectAnchorWorker ) def perform(project_anchor_id, year, quarter, selected_org_unit_ids = nil, options = {}) + if ENV.fetch("SDKQ_FORK_ENABLED", "false") == "true" + command = "time bundle exec rails runner 'InvoiceForProjectAnchorWorker.new.really_perform(#{project_anchor_id}, #{year}, #{quarter}, [\"" + selected_org_unit_ids[0] + "\"])'" + puts("forking invoice", command) + puts(exec(command)) + else + really_perform(project_anchor_id, year, quarter, selected_org_unit_ids, options) + end + end + + def really_perform(project_anchor_id, year, quarter, selected_org_unit_ids = nil, options = {}) default_options = { slice_size: 25 }