songtianlun
bf2ff282bb
- Change class names from Worker to Job for better alignment with Rails convention. - Includes changes in BatchGenerateWeatherArtsJob, CleanAhoyDataJob, GenerateWeatherArtJob, and RefreshSitemapJob classes. This refactoring improves the clarity and consistency of the codebase by adhering to established naming conventions, making it easier for new developers to understand the role of these classes within the application.
30 lines
862 B
Ruby
30 lines
862 B
Ruby
# app/jobs/clean_ahoy_data_job.rb
|
|
class CleanAhoyDataJob < ApplicationJob
|
|
queue_as :default
|
|
|
|
def perform
|
|
cleanup_old_events
|
|
cleanup_old_visits
|
|
log_cleanup_results
|
|
end
|
|
|
|
private
|
|
|
|
def cleanup_old_events
|
|
cutoff_date = 3.months.ago
|
|
deleted_events_count = Ahoy::Event.where("time < ?", cutoff_date).delete_all
|
|
Rails.logger.info "Deleted #{deleted_events_count} old Ahoy events"
|
|
end
|
|
|
|
def cleanup_old_visits
|
|
cutoff_date = 3.months.ago
|
|
deleted_visits_count = Ahoy::Visit.where("started_at < ?", cutoff_date).delete_all
|
|
Rails.logger.info "Deleted #{deleted_visits_count} old Ahoy visits"
|
|
end
|
|
|
|
def log_cleanup_results
|
|
Rails.logger.info "Ahoy cleanup completed at #{Time.current}"
|
|
Rails.logger.info "Remaining events: #{Ahoy::Event.count}"
|
|
Rails.logger.info "Remaining visits: #{Ahoy::Visit.count}"
|
|
end
|
|
end |