Sha256: bf119b46c7d3509ab1f04bdacb96b2c67ec17b5d4e256b4aca67825b9dba7d75

Contents?: true

Size: 1.31 KB

Versions: 20

Compression:

Stored size: 1.31 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 = "#{Rails.application.class.parent_name.underscore}/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

20 entries across 20 versions & 2 rubygems

Version Path
mvpkit-2.0.2 lib/tasks/sitemap.rake
mvpkit-2.0.1 lib/tasks/sitemap.rake
mvpkit-2.0.0 lib/tasks/sitemap.rake
mvpkit-1.1.2 lib/tasks/sitemap.rake
mvpkit-1.1.1 lib/tasks/sitemap.rake
mvpkit-1.1.0 lib/tasks/sitemap.rake
mvpkit-1.0.4 lib/tasks/sitemap.rake
mvpkit-1.0.3 lib/tasks/sitemap.rake
mvpkit-1.0.2 lib/tasks/sitemap.rake
mvpkit-1.0.1 lib/tasks/sitemap.rake
mvpkit-1.0.0 lib/tasks/sitemap.rake
mvpkit-0.8.1 lib/tasks/sitemap.rake
mvpkit-0.8.0 lib/tasks/sitemap.rake
minimum_viable_product-0.7.15 lib/tasks/sitemap.rake
minimum_viable_product-0.7.14 lib/tasks/sitemap.rake
minimum_viable_product-0.7.13 lib/tasks/sitemap.rake
minimum_viable_product-0.7.12 lib/tasks/sitemap.rake
minimum_viable_product-0.7.11 lib/tasks/sitemap.rake
minimum_viable_product-0.7.10 lib/tasks/sitemap.rake
minimum_viable_product-0.7.9 lib/tasks/sitemap.rake