Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert optional keyword arg to options #2804

Merged
merged 1 commit into from
Sep 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/models/deletion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ def restore_to_storage
end

def purge_fastly
Fastly.delay.purge("gems/#{@version.full_name}.gem")
Fastly.delay.purge("quick/Marshal.4.8/#{@version.full_name}.gemspec.rz")
Fastly.delay.purge(path: "gems/#{@version.full_name}.gem")
Fastly.delay.purge(path: "quick/Marshal.4.8/#{@version.full_name}.gemspec.rz")
end

def update_search_index
Expand Down
6 changes: 3 additions & 3 deletions lib/fastly.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ class Net::HTTP::Purge < Net::HTTPRequest
end

class Fastly
def self.purge(path, soft: false)
def self.purge(options = {})
return unless ENV["FASTLY_DOMAINS"]
ENV["FASTLY_DOMAINS"].split(",").each do |domain|
url = "https://#{domain}/#{path}"
headers = soft ? { "Fastly-Soft-Purge" => 1 } : {}
url = "https://#{domain}/#{options[:path]}"
headers = options[:soft] ? { "Fastly-Soft-Purge" => 1 } : {}
headers["Fastly-Key"] = ENV["FASTLY_API_KEY"]

response = RestClient::Request.execute(method: :purge,
Expand Down
6 changes: 3 additions & 3 deletions lib/gem_cache_purger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ def self.call(gem_name)
# We need to purge from Fastly and from Memcached
["info/#{gem_name}", "names"].each do |path|
Rails.cache.delete(path)
Fastly.delay.purge(path, soft: true)
Fastly.delay.purge(path: path, soft: true)
end

Rails.cache.delete("deps/v1/#{gem_name}")
Fastly.delay.purge("versions", soft: true)
Fastly.delay.purge("gem/#{gem_name}", soft: true)
Fastly.delay.purge(path: "versions", soft: true)
Fastly.delay.purge(path: "gem/#{gem_name}", soft: true)
end
end
4 changes: 2 additions & 2 deletions test/unit/deletion_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ class DeletionTest < ActiveSupport::TestCase
end

should "purge fastly" do
Fastly.expects(:purge).with("gems/#{@version.full_name}.gem").times(2)
Fastly.expects(:purge).with("quick/Marshal.4.8/#{@version.full_name}.gemspec.rz").times(2)
Fastly.expects(:purge).with(path: "gems/#{@version.full_name}.gem").times(2)
Fastly.expects(:purge).with(path: "quick/Marshal.4.8/#{@version.full_name}.gemspec.rz").times(2)

Delayed::Worker.new.work_off
end
Expand Down
2 changes: 1 addition & 1 deletion test/unit/fastly_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class FastlyTest < ActiveSupport::TestCase
context ".purge" do
should "purge for each domain" do
RestClient::Request.expects(:execute).times(2).returns("{}")
Fastly.purge("some-url")
Fastly.purge(path: "some-url")
end
end
end
8 changes: 4 additions & 4 deletions test/unit/gem_cache_purger_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ class GemCachePurgerTest < ActiveSupport::TestCase
end

should "purge cdn cache" do
Fastly.expects(:purge).with("info/#{@gem_name}", soft: true)
Fastly.expects(:purge).with("gem/#{@gem_name}", soft: true)
Fastly.expects(:purge).with("names", soft: true)
Fastly.expects(:purge).with("versions", soft: true)
Fastly.expects(:purge).with(path: "info/#{@gem_name}", soft: true)
Fastly.expects(:purge).with(path: "gem/#{@gem_name}", soft: true)
Fastly.expects(:purge).with(path: "names", soft: true)
Fastly.expects(:purge).with(path: "versions", soft: true)

GemCachePurger.call(@gem_name)
Delayed::Worker.new.work_off
Expand Down