refactor: improve logging in weather arts worker
- Added logging for skipped recent cities. - Enhanced logging for selected cities after filtering. This refactor improves the observability of the city selection process in the BatchGenerateWeatherArtsWorker. The added logs provide better insight during debugging and monitoring, allowing developers to track recent selections and identify any issues related to city filtering more effectively.
This commit is contained in:
parent
104597e3ba
commit
269e5ef553
@ -69,14 +69,15 @@ class BatchGenerateWeatherArtsWorker
|
||||
end
|
||||
|
||||
def select_cities(recent_city, countries, limit)
|
||||
cutoff_time = Time.current - GENERATION_INTERVAL
|
||||
Rails.logger.debug "Select Cities with limit: #{limit}, in #{countries.size} countries."
|
||||
Rails.logger.debug "Skip Cities(count: #{recent_city.count}) list: #{recent_city.map(&:name).join(', ')}."
|
||||
# 第一阶段:筛选 active 城市, 排除最近生成过的城市
|
||||
active_cities = City.where.not(id: recent_city.pluck(:id))
|
||||
.where(active: true, country_id: countries.map(&:id)).limit(limit).to_a
|
||||
selected = active_cities.first(limit)
|
||||
remaining = limit - selected.size
|
||||
Rails.logger.debug "Step1: Selected #{selected.size} cities with active city."
|
||||
Rails.logger.debug "==recent selected city list: #{selected.map(&:name).join(', ')}."
|
||||
|
||||
return selected if remaining <= 0
|
||||
|
||||
@ -101,6 +102,7 @@ class BatchGenerateWeatherArtsWorker
|
||||
Rails.logger.debug "== No valid cities found in country: [#{country.name}]"
|
||||
end
|
||||
end
|
||||
Rails.logger.debug "==recent selected city list: #{selected.map(&:name).join(', ')}."
|
||||
Rails.logger.debug "Finished selected #{selected.size} cities."
|
||||
selected
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user