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

Serve from cache when response.code != 200 #21

Merged
merged 1 commit into from
Oct 27, 2022
Merged
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
5 changes: 3 additions & 2 deletions files/enc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def pop
end

class FactUploadError < StandardError; end
class NodeRetrievalError < StandardError; end

require 'etc'
require 'net/http'
Expand Down Expand Up @@ -272,7 +273,7 @@ def enc(certname)
response = http.request(req)

unless response.code == "200"
raise "Error retrieving node #{certname}: #{response.class}\nCheck Foreman's /var/log/foreman/production.log for more information."
raise NodeRetrievalError, "Error retrieving node #{certname}: #{response.class}\nCheck Foreman's /var/log/foreman/production.log for more information."
end
response.body
end
Expand Down Expand Up @@ -443,7 +444,7 @@ def watch_and_send_facts(parallel)
result = enc(certname)
cache(certname, result)
end
rescue TimeoutError, SocketError, Errno::EHOSTUNREACH, Errno::ECONNREFUSED, FactUploadError => e
rescue TimeoutError, SocketError, Errno::EHOSTUNREACH, Errno::ECONNREFUSED, NodeRetrievalError, FactUploadError => e
$stderr.puts "Serving cached ENC: #{e}"
# Read from cache, we got some sort of an error.
result = read_cache(certname)
Expand Down