today_ai_weather/app/jobs/batch_generate_weather_arts_job.rb
songtianlun 853a1d03ce refactor: clean up ai_service code formatting
- Adjust formatting for message parameters in the chat call
- Eliminate unnecessary blank lines in generate_prompt_request method
- Ensure consistent styles for arrays and block indentation

These changes improve code readability and maintain consistency in
formatting for better maintainability without altering functionality.
2025-01-22 16:50:21 +08:00

34 lines
807 B
Ruby

class BatchGenerateWeatherArtsJob < ApplicationJob
queue_as :default
def perform(*args)
start_time = Time.current
max_duration = 50.minutes
cities_to_process = get_eligible_cities
cities_to_process.each do |city|
break if Time.current - start_time > max_duration
GenerateWeatherArtJob.perform_now(city)
sleep 1.minute # 确保不超过API限制
end
end
private
def get_eligible_cities
City.active
.where(active: true)
.where("last_weather_fetch IS NULL OR last_weather_fetch < ?", Date.today)
# .select { |city| early_morning_in_timezone?(city.timezone) }
end
# def early_morning_in_timezone?(timezone)
# return false if timezone.blank?
# time = Time.current.in_time_zone(timezone)
# time.hour == 2
# end
end