Merge pull request #520 from Supermathie/master
cdn prefetch: modify to pull files one-by-one
This commit is contained in:
commit
664915fcd2
|
@ -14,7 +14,7 @@ task 'assets:prestage' => :environment do |t|
|
||||||
end
|
end
|
||||||
|
|
||||||
# pre-stage css/js only for now
|
# pre-stage css/js only for now
|
||||||
a = get_assets("locales/") + get_assets("")
|
assets = get_assets("locales/") + get_assets("")
|
||||||
puts "pre staging: #{a.join(' ')}"
|
puts "pre staging: #{a.join(' ')}"
|
||||||
|
|
||||||
# makes testing simpler leaving this here
|
# makes testing simpler leaving this here
|
||||||
|
@ -27,19 +27,25 @@ task 'assets:prestage' => :environment do |t|
|
||||||
http.use_ssl = true
|
http.use_ssl = true
|
||||||
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
||||||
|
|
||||||
|
failed_assets = []
|
||||||
request = Net::HTTP::Post.new(uri.request_uri)
|
request = Net::HTTP::Post.new(uri.request_uri)
|
||||||
request.set_form_data(
|
assets.each do |asset|
|
||||||
"id" => config["id"],
|
request.set_form_data(
|
||||||
"login" => config["login"],
|
"id" => config["id"],
|
||||||
"passwd" => config["password"],
|
"login" => config["login"],
|
||||||
"json" => {"prefetch_paths" => a.join("\n")}.to_json
|
"passwd" => config["password"],
|
||||||
)
|
"json" => {"prefetch_paths" => asset}.to_json
|
||||||
|
)
|
||||||
|
|
||||||
response = http.request(request)
|
response = http.request(request)
|
||||||
json = JSON.parse(response.body)
|
json = JSON.parse(response.body)
|
||||||
if json["status"] != "ok"
|
if json["status"] != "ok"
|
||||||
raise "Failed to pre-stage"
|
failed_assets.push(asset)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if failed_assets.length > 0
|
||||||
|
raise "Failed to pre-stage #{failed_assets.length}/#{assets.length} files"
|
||||||
end
|
end
|
||||||
puts "Done (took: #{((Time.now - start) * 1000.0).to_i}ms)"
|
puts "Done (took: #{((Time.now - start) * 1000.0).to_i}ms)"
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue