Skip to content

Commit

Permalink
Merge pull request #319 from BLSQ/change-invoice-ttl
Browse files Browse the repository at this point in the history
ttl for worker
  • Loading branch information
mestachs authored Sep 23, 2024
2 parents 1260a5a + feb8843 commit 81b91fc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/workers/dhis2_snapshot_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
)

Expand Down
15 changes: 14 additions & 1 deletion app/workers/invoice_for_project_anchor_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,27 @@ 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("-")
}
)

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
}
Expand Down

0 comments on commit 81b91fc

Please sign in to comment.