Sha256: 19b1f875a7a017bf7f686e052ad6a300f3322d49de2d44ed875e5dce2d6883e2

Contents?: true

Size: 1.28 KB

Versions: 46

Compression:

Stored size: 1.28 KB

Contents

require 'fog'

namespace :sitemap do
  desc 'Upload the sitemap files to S3'
  task upload: :environment do
    puts "Starting sitemap upload to S3..."

    connection = Fog::Storage.new({
      :provider                 => 'AWS',
      :aws_access_key_id        => ENV['AWS_ACCESS_KEY_ID'],
      :aws_secret_access_key    => ENV['AWS_SECRET_ACCESS_KEY']
    })

    directory = connection.directories.get(ENV['AWS_S3_BUCKET'])

    Dir.entries(File.join(Rails.root, "tmp", "sitemaps")).each do |file_name|
      next if ['.', '..', '.DS_Store'].include? file_name
      path = "#{ENV['PROJECT_NAME']}/sitemaps/#{file_name}"
      file = File.new(File.join(Rails.root, "tmp", "sitemaps", file_name))

      begin
        file = directory.files.create(
          :body => file,
          :key  => path,
          :public => true
        )
        # object = bucket.objects[path]
        # object.write(file: file)
      rescue Exception => e
        raise e
      end
      puts "Saved #{file_name} to S3"
    end
  end

  desc 'Create the sitemap, then upload it to S3 and ping the search engines'
  task worker: :environment do
    Rake::Task["sitemap:create"].invoke
    Rake::Task["sitemap:upload"].invoke
    SitemapGenerator::Sitemap.ping_search_engines(MVP::Engine.routes.url_helpers.sitemap_url)
  end
end

Version data entries

46 entries across 46 versions & 1 rubygems

Version Path
minimum_viable_product-0.7.8 lib/tasks/sitemap.rake
minimum_viable_product-0.7.7 lib/tasks/sitemap.rake
minimum_viable_product-0.7.6 lib/tasks/sitemap.rake
minimum_viable_product-0.7.5 lib/tasks/sitemap.rake
minimum_viable_product-0.7.4 lib/tasks/sitemap.rake
minimum_viable_product-0.7.3 lib/tasks/sitemap.rake
minimum_viable_product-0.7.2 lib/tasks/sitemap.rake
minimum_viable_product-0.7.1 lib/tasks/sitemap.rake
minimum_viable_product-0.7.0 lib/tasks/sitemap.rake
minimum_viable_product-0.6.7 lib/tasks/sitemap.rake
minimum_viable_product-0.6.6 lib/tasks/sitemap.rake
minimum_viable_product-0.6.5 lib/tasks/sitemap.rake
minimum_viable_product-0.6.4 lib/tasks/sitemap.rake
minimum_viable_product-0.6.3 lib/tasks/sitemap.rake
minimum_viable_product-0.6.2 lib/tasks/sitemap.rake
minimum_viable_product-0.6.1 lib/tasks/sitemap.rake
minimum_viable_product-0.6.0 lib/tasks/sitemap.rake
minimum_viable_product-0.5.7 lib/tasks/sitemap.rake
minimum_viable_product-0.5.6 lib/tasks/sitemap.rake
minimum_viable_product-0.5.5 lib/tasks/sitemap.rake