Class: UploadSitemapWorker
- Inherits:
-
ApplicationWorker
- Object
- ApplicationWorker
- UploadSitemapWorker
- Defined in:
- app/workers/upload_sitemap_worker.rb
Overview
This worker generates the sitemap and uploads it to the S3 bucket. It uses the SitemapGenerator gem to create the sitemap files and the AWS SDK to upload them. The sitemap files are stored in the public directory of the Rails application. The worker is designed to be run periodically to keep the sitemap up to date (it will be run everyday at 20:00 UTC). It cleans up old sitemap files before generating new ones to ensure that only the latest sitemap is available.
Instance Method Summary collapse
Methods inherited from ApplicationWorker
Instance Method Details
#perform ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/workers/upload_sitemap_worker.rb', line 10 def perform SitemapGenerator::Utilities.clean_files SitemapGenerator::Interpreter.run s3 = Aws::S3::Resource.new(region: Figaro.env.aws_region!) sitemaps = Dir.entries(Rails.public_path).select do |file| file.include?('.xml.gz') end sitemaps.each do |filename| target_file = Rails.public_path.join(filename).to_s next unless File.exist?(target_file) file_path = target_file.freeze target_obj = s3.bucket(Figaro.env.AWS_DOCS_BUCKET!).object(filename) target_obj.upload_file(file_path) end end |