feat: improve worker logging

- Added current time logging to the worker to help debug and
  analyze processing times
- Cleaned up assets initializer file
This commit is contained in:
songtianlun 2025-02-15 12:30:48 +08:00
parent 936db76437
commit 2042732787
2 changed files with 7 additions and 7 deletions

View File

@ -19,11 +19,11 @@ class BatchGenerateWeatherArtsWorker
cities_to_process.each do |city| cities_to_process.each do |city|
if within_sunrise_time?(city) if within_sunrise_time?(city)
Rails.logger.info "Generating weather art for #{city.name}" Rails.logger.info "Generating weather art for #{city.name} (time: [#{city.formatted_current_time(:all)}])"
GenerateWeatherArtWorker.perform_async(city.id) GenerateWeatherArtWorker.perform_async(city.id)
processed_cities << city.name processed_cities << city.name
else else
Rails.logger.info "Skipping #{city.name} due to local time not being within sunrise hours." Rails.logger.info "Skipping #{city.name} (time: [#{city.formatted_current_time(:all)}]) due to local time not being within sunrise hours."
skipped_cities << city.name skipped_cities << city.name
end end
sleep SLEEP_DURATION sleep SLEEP_DURATION
@ -41,7 +41,7 @@ class BatchGenerateWeatherArtsWorker
.where.not(image_attachment: nil) .where.not(image_attachment: nil)
.count .count
[DAILY_GENERATION_LIMIT - today_generations, 0].max [ DAILY_GENERATION_LIMIT - today_generations, 0 ].max
end end
def print_cities_list(cities, start_time) def print_cities_list(cities, start_time)
@ -56,15 +56,16 @@ class BatchGenerateWeatherArtsWorker
def within_sunrise_time?(city) def within_sunrise_time?(city)
local_time = get_local_time(city) local_time = get_local_time(city)
Rails.logger.info "#{city.name} now hour: #{local_time.hour}"
local_time.hour >= 8 && local_time.hour <= 18 local_time.hour >= 8 && local_time.hour <= 18
end end
def get_local_time(city) def get_local_time(city)
return Time.current unless city return Time.current unless city
timezone_info = city.country&.timezones&.first timezone_info = eval(city.country.timezones).first
return Time.current unless timezone_info return Time.current unless timezone_info
timezone = ActiveSupport::TimeZone["zoneName"] || timezone = ActiveSupport::TimeZone[timezone_info["zoneName"]] ||
ActiveSupport::TimeZone["UTC"] ActiveSupport::TimeZone["UTC"]
Time.current.in_time_zone(timezone) Time.current.in_time_zone(timezone)
end end
@ -105,4 +106,4 @@ class BatchGenerateWeatherArtsWorker
active_cities active_cities
end end
end end
end end

View File

@ -10,4 +10,3 @@ Rails.application.config.assets.version = "1.0"
# Rails.application.config.assets.precompile += %w( *.png *.jpg *.jpeg *.gif ) # Rails.application.config.assets.precompile += %w( *.png *.jpg *.jpeg *.gif )
# Rails.application.config.assets.paths << Rails.root.join("app/assets/builds") # Rails.application.config.assets.paths << Rails.root.join("app/assets/builds")
# Rails.application.config.assets.precompile += %w( *.png *.jpg *.jpeg *.gif ) # Rails.application.config.assets.precompile += %w( *.png *.jpg *.jpeg *.gif )