Sha256: 7daea6ed6a10359dc8c6a4106b2855e7ba37a83481145f2ace2b08983099875b

Contents?: true

Size: 1.15 KB

Versions: 9

Compression:

Stored size: 1.15 KB

Contents

module Workarea
  module Tasks
    module Cache
      extend self

      def prime_images
        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
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
workarea-core-3.5.27 lib/workarea/tasks/cache.rb
workarea-core-3.5.26 lib/workarea/tasks/cache.rb
workarea-core-3.5.25 lib/workarea/tasks/cache.rb
workarea-core-3.5.23 lib/workarea/tasks/cache.rb
workarea-core-3.5.22 lib/workarea/tasks/cache.rb
workarea-core-3.5.21 lib/workarea/tasks/cache.rb
workarea-core-3.5.20 lib/workarea/tasks/cache.rb
workarea-core-3.5.19 lib/workarea/tasks/cache.rb
workarea-core-3.5.18 lib/workarea/tasks/cache.rb