Fix RuboCop offenses

This commit is contained in:
Mahima Singh 2025-12-24 15:06:22 +05:30
parent fe9f98e281
commit a4abe2652a
3 changed files with 39 additions and 29 deletions

View file

@ -302,13 +302,15 @@ module Vmpooler
# Use a single pipeline to fetch all queue counts at once for better performance # Use a single pipeline to fetch all queue counts at once for better performance
results = backend.pipelined do |pipeline| results = backend.pipelined do |pipeline|
# Order matters - we'll use indices to extract values # Order matters - we'll use indices to extract values
pools.each { |pool| pipeline.scard("vmpooler__provisioning__request#{pool['name']}") } # 0..n-1 pools.each do |pool|
pools.each { |pool| pipeline.scard("vmpooler__provisioning__processing#{pool['name']}") } # n..2n-1 pipeline.scard("vmpooler__provisioning__request#{pool['name']}") # 0..n-1
pools.each { |pool| pipeline.scard("vmpooler__odcreate__task#{pool['name']}") } # 2n..3n-1 pipeline.scard("vmpooler__provisioning__processing#{pool['name']}") # n..2n-1
pools.each { |pool| pipeline.scard("vmpooler__pending__#{pool['name']}") } # 3n..4n-1 pipeline.scard("vmpooler__odcreate__task#{pool['name']}") # 2n..3n-1
pools.each { |pool| pipeline.scard("vmpooler__ready__#{pool['name']}") } # 4n..5n-1 pipeline.scard("vmpooler__pending__#{pool['name']}") # 3n..4n-1
pools.each { |pool| pipeline.scard("vmpooler__running__#{pool['name']}") } # 5n..6n-1 pipeline.scard("vmpooler__ready__#{pool['name']}") # 4n..5n-1
pools.each { |pool| pipeline.scard("vmpooler__completed__#{pool['name']}") } # 6n..7n-1 pipeline.scard("vmpooler__running__#{pool['name']}") # 5n..6n-1
pipeline.scard("vmpooler__completed__#{pool['name']}") # 6n..7n-1
end
pipeline.get('vmpooler__tasks__clone') # 7n pipeline.get('vmpooler__tasks__clone') # 7n
pipeline.get('vmpooler__tasks__ondemandclone') # 7n+1 pipeline.get('vmpooler__tasks__ondemandclone') # 7n+1
end end

View file

@ -10,14 +10,21 @@ module Vmpooler
api_prefix = "/api/v#{api_version}" api_prefix = "/api/v#{api_version}"
# Simple in-memory cache for status endpoint # Simple in-memory cache for status endpoint
@@status_cache = {} @status_cache = {}
@@status_cache_mutex = Mutex.new @status_cache_mutex = Mutex.new
STATUS_CACHE_TTL = 30 # seconds STATUS_CACHE_TTL = 30 # seconds
class << self
attr_accessor :status_cache, :status_cache_mutex
end
@status_cache ||= {}
@status_cache_mutex ||= Mutex.new
# Clear cache (useful for testing) # Clear cache (useful for testing)
def self.clear_status_cache def self.clear_status_cache
@@status_cache_mutex.synchronize do @status_cache_mutex.synchronize do
@@status_cache.clear @status_cache.clear
end end
end end
@ -478,18 +485,19 @@ module Vmpooler
# Cache helper methods for status endpoint # Cache helper methods for status endpoint
def get_cached_status(cache_key) def get_cached_status(cache_key)
@@status_cache_mutex.synchronize do self.class.status_cache_mutex.synchronize do
cached = @@status_cache[cache_key] cached = self.class.status_cache[cache_key]
if cached && (Time.now - cached[:timestamp]) < STATUS_CACHE_TTL if cached && (Time.now - cached[:timestamp]) < STATUS_CACHE_TTL
return cached[:data] return cached[:data]
end end
nil nil
end end
end end
def set_cached_status(cache_key, data) def set_cached_status(cache_key, data)
@@status_cache_mutex.synchronize do self.class.status_cache_mutex.synchronize do
@@status_cache[cache_key] = { self.class.status_cache[cache_key] = {
data: data, data: data,
timestamp: Time.now timestamp: Time.now
} }