diff --git a/app/workers/batch_generate_weather_arts_worker.rb b/app/workers/batch_generate_weather_arts_worker.rb index 3569bec..c2fce30 100644 --- a/app/workers/batch_generate_weather_arts_worker.rb +++ b/app/workers/batch_generate_weather_arts_worker.rb @@ -47,7 +47,7 @@ class BatchGenerateWeatherArtsWorker FROM weather_arts GROUP BY city_id ) latest_arts ON cities.id = latest_arts.city_id") - .where("latest_arts.last_generation_time < ?", cutoff_time) + .where("latest_arts.last_generation_time > ?", cutoff_time) end def calculate_remaining_slots @@ -69,8 +69,8 @@ class BatchGenerateWeatherArtsWorker end def select_cities(recent_city, countries, limit) - 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(', ')}." + 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 @@ -97,12 +97,12 @@ class BatchGenerateWeatherArtsWorker .first(remaining_every_country_count) if c.any? # 检查是否有有效的城市 Rails.logger.debug "== Selected city [#{c.first.name}] in country: [#{country.name}]" - selected << c + selected += c else 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 "==recent selected city list: #{selected.map(&:name).join(', ')}." if selected.any? Rails.logger.debug "Finished selected #{selected.size} cities." selected end