Sha256: aa67443703126e7227fcc6bef8376b9c01fec8439565dd31753c2ec6d6e703d7

Contents?: true

Size: 1.29 KB

Versions: 30

Compression:

Stored size: 1.29 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 = "__PROJECT_NAME_SLUG__/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(Rails.application.routes.url_helpers.sitemap_url)
  end
end

Version data entries

30 entries across 29 versions & 2 rubygems

Version Path
minimum_viable_product-0.0.34 lib/tasks/sitemap.rake
minimum_viable_product-0.0.33 lib/tasks/sitemap.rake
minimum_viable_product-0.0.32 lib/tasks/sitemap.rake
minimum_viable_product-0.0.30 lib/tasks/sitemap.rake
minimum_viable_product-0.0.29 lib/tasks/sitemap.rake
minimum_viable_product-0.0.27 lib/tasks/sitemap.rake
minimum_viable_product-0.0.26 lib/tasks/sitemap.rake
minimum_viable_product-0.0.25 lib/tasks/sitemap.rake
minimum_viable_product-0.0.24 lib/tasks/sitemap.rake
minimum_viable_product-0.0.23 lib/tasks/sitemap.rake
minimum_viable_product-0.0.22 lib/tasks/sitemap.rake
minimum_viable_product-0.0.21 lib/tasks/sitemap.rake
minimum_viable_product-0.0.20 lib/tasks/sitemap.rake
minimum_viable_product-0.0.19 lib/tasks/sitemap.rake
minimum_viable_product-0.0.18 lib/tasks/sitemap.rake
minimum_viable_product-0.0.17 lib/tasks/sitemap.rake
minimum_viable_product-0.0.16 lib/tasks/sitemap.rake
minimum_viable_product-0.0.15 lib/tasks/sitemap.rake
minimum_viable_product-0.0.14 lib/tasks/sitemap.rake
minimum_viable_product-0.0.13 lib/tasks/sitemap.rake