Skip to content

Commit

Permalink
Some more tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
mayorova committed Oct 10, 2024
1 parent 8deaae6 commit a96314b
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 5 deletions.
2 changes: 2 additions & 0 deletions app/services/synchronization/nowait_lock_service.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'three_scale/patterns/service'

class Synchronization::NowaitLockService < ThreeScale::Patterns::Service
# @param str_resource [String] a lock key
# @param timeout [Integer] milliseconds lock timeout
Expand Down
2 changes: 2 additions & 0 deletions app/services/synchronization/unsafe_unlock_service.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'three_scale/patterns/service'

class Synchronization::UnsafeUnlockService < ThreeScale::Patterns::Service
# unconditional lock release, dangerous to create race conditions based on a redlock key
# should only be used for manual intervention in case of extraordinary circumstances
Expand Down
Empty file removed curl-output.txt
Empty file.
7 changes: 4 additions & 3 deletions lib/tasks/sidekiq/cleanup.rake
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ require 'three_scale/sidekiq_batch_cleanup_service'
namespace :sidekiq do
desc 'cleanup BID-* keys from sidekiq-batch, specify the max age in seconds as an argument'
task :cleanup_batches, [:max_age_seconds] => :environment do |task, args|
max_age_seconds = Integer(args[:max_age_seconds])
params = args[:max_age_seconds] ? { max_age_seconds: Integer(args[:max_age_seconds]) } : {}

Rails.logger.info "Cleaning up BID-* keys older than #{max_age_seconds.seconds.in_hours} hours from sidekiq-batch..."
message = params[:max_age_seconds] ? "#{params[:max_age_seconds].seconds.in_hours} hours" : "the default age"
puts "Cleaning up the sidekiq-batch BID-* keys older than #{message}"

ThreeScale::SidekiqBatchCleanupService.call(max_age_seconds: max_age_seconds)
ThreeScale::SidekiqBatchCleanupService.call(**params)
end
end
File renamed without changes.
14 changes: 12 additions & 2 deletions lib/three_scale/sidekiq_batch_cleanup_service.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'progress_counter'

require Rails.root.join('app/lib/three_scale/patterns/service')
require 'three_scale/patterns/service'

module ThreeScale
class SidekiqBatchCleanupService < ThreeScale::Patterns::Service
Expand All @@ -22,7 +22,7 @@ def initialize(max_age_seconds: DEFAULT_MAX_AGE_SECONDS)

def call
total = redis.dbsize
Rails.logger.info "Total number of keys: #{total}, will delete keys with TTL less than #{bid_max_ttl.seconds.in_hours} hours"
logger.info "Total number of keys: #{total}, will delete BID-* keys with TTL less than #{bid_max_ttl.seconds.in_hours} hours"

scan_enum = System.redis.scan_each(match: 'BID-*', type: 'hash', count: MAX_FETCH_COUNT)

Expand Down Expand Up @@ -50,5 +50,15 @@ def each_with_progress_counter(enumerable, count)
progress.call
end
end

# This logger just prints out a message to STDOUT, with new line before and after.
# New line before is to make progress log look better
def logger
@logger ||= begin
log = ActiveSupport::Logger.new($stdout)
log.formatter = ->(_, _, _, msg) { "\n#{msg.is_a?(String) ? msg : msg.inspect}\n" }
log
end
end
end
end

0 comments on commit a96314b

Please sign in to comment.