Skip to content

Commit

Permalink
Merge branch 'slave-for-delete' into 'master'
Browse files Browse the repository at this point in the history
DEX-2327 use replica to select ids in BaseDeleteStaleItemsJob

See merge request nstmrt/rubygems/outbox!96
  • Loading branch information
bibendi committed Jun 5, 2024
2 parents abe6180 + ec69529 commit 900618a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased] - yyyy-mm-dd

## [6.5.0] - 2024-06-05

### Added

- use db replica to select stale item ids

### Fixed

- fix undefined local variable or method labels for Sbmt::Outbox::V2::Poller

## [6.4.3] - 2024-05-16

### Fixed
Expand Down
7 changes: 5 additions & 2 deletions app/jobs/sbmt/outbox/base_delete_stale_items_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,12 @@ def validate_retention!(duration)
def delete_stale_items(waterline)
logger.log_info("Start deleting #{box_type} items for #{box_name} older than #{waterline}")

scope = item_class.where("created_at < ?", waterline)
loop do
ids = Outbox.database_switcher.use_slave do
item_class.where("created_at < ?", waterline).limit(BATCH_SIZE).ids
end
break if ids.empty?

while (ids = scope.limit(BATCH_SIZE).ids).present?
item_class.where(id: ids).delete_all
sleep SLEEP_TIME
end
Expand Down
2 changes: 1 addition & 1 deletion lib/sbmt/outbox/v2/poller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def poll(task)
end
end
rescue Cutoff::CutoffExceededError
box_worker.job_timeout_counter.increment(labels)
box_worker.job_timeout_counter.increment(task.yabeda_labels)
logger.log_info("Lock timeout while processing #{task.resource_key} at id #{last_id}")
end

Expand Down
2 changes: 1 addition & 1 deletion lib/sbmt/outbox/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module Sbmt
module Outbox
VERSION = "6.4.3"
VERSION = "6.5.0"
end
end

0 comments on commit 900618a

Please sign in to comment.