Sha256: f0756f65caec65bf9ac25655647ed56279511d87d48006c53f9582885ddbd7ca

Contents?: true

Size: 1.1 KB

Versions: 53

Compression:

Stored size: 1.1 KB

Contents

namespace :workarea do
  namespace :cache do
    desc 'Prime images cache'
    task prime_images: :environment do
      include Rails.application.routes.url_helpers
      include Workarea::Storefront::ProductsHelper
      include Workarea::Core::Engine.routes.url_helpers

      built_in_jobs = [:thumb, :gif, :jpg, :png, :strip, :convert, :optimized]

      jobs = Dragonfly.app(:workarea).processor_methods.reject do |job|
        built_in_jobs.include?(job)
      end

      Workarea::Catalog::Product.all.each_by(50) do |product|
        product.images.each do |image|
          jobs.each do |job|
            url = URI.join(
              "https://#{Workarea.config.host}",
              dynamic_product_image_url(
                image.product.slug,
                image.option,
                image.id,
                job,
                only_path: true
              )
            ).to_s

            begin
              `curl #{url}`
              puts "Downloaded image #{url}"
            rescue StandardError => e
              puts e.inspect
            end
          end
        end
      end
    end
  end
end

Version data entries

53 entries across 53 versions & 1 rubygems

Version Path
workarea-core-3.4.22 lib/tasks/cache.rake
workarea-core-3.5.0 lib/tasks/cache.rake
workarea-core-3.4.21 lib/tasks/cache.rake
workarea-core-3.5.0.beta.1 lib/tasks/cache.rake
workarea-core-3.4.20 lib/tasks/cache.rake
workarea-core-3.4.19 lib/tasks/cache.rake
workarea-core-3.4.18 lib/tasks/cache.rake
workarea-core-3.4.17 lib/tasks/cache.rake
workarea-core-3.4.16 lib/tasks/cache.rake
workarea-core-3.4.15 lib/tasks/cache.rake
workarea-core-3.4.14 lib/tasks/cache.rake
workarea-core-3.4.13 lib/tasks/cache.rake
workarea-core-3.4.12 lib/tasks/cache.rake