-
-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
No expectation this works like this, is basically pseudo-code in parts.
- Loading branch information
Showing
9 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
require 'net/http' | ||
|
||
class Net::HTTP::Purge < Net::HTTP::Get | ||
METHOD = 'PURGE' | ||
end | ||
|
||
class Net::HTTP::Ban < Net::HTTP::Get | ||
METHOD = 'BAN' | ||
end | ||
|
||
## | ||
# Job to notify a cache of URLs to be purged or banned, given an object | ||
# (that must have a cached_urls method). | ||
# | ||
# Examples: | ||
# NotifyCacheJob.perform(InfoRequest.first) | ||
# NotifyCacheJob.perform(FoiAttachment.first) | ||
# NotifyCacheJob.perform(Comment.first) | ||
# | ||
class NotifyCacheJob < ApplicationJob | ||
queue_as :default | ||
|
||
def perform(object) | ||
urls = object.cached_urls | ||
hosts = AlaveteliConfiguration.varnish_hosts | ||
hosts.each do |host| | ||
Net::HTTP.start('www.whatdotheyknow.com', 80, host, 6081) do |http| | ||
urls.each do |url| | ||
if url.include? '^' | ||
request = Net::HTTP::Ban.new(url) | ||
else | ||
request = Net::HTTP::Purge.new(url) | ||
end | ||
response = http.request(request) | ||
result = response.code | ||
if result == "200" | ||
Rails.logger.debug("PURGE: Purged URL #{url} at #{host}: #{result}") | ||
else | ||
Rails.logger.warn( | ||
"PURGE: Unable to purge URL #{url} at #{host}: status #{result}" | ||
) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters