mirror of
https://github.com/neocities/neocities.git
synced 2025-04-24 17:22:35 +02:00
Better error handling for screenshot and thumbnail workers, hacky fix for lets encrypt cert issue that's temporary
This commit is contained in:
parent
4382eec54b
commit
2a3b8593df
4 changed files with 25 additions and 26 deletions
18
Rakefile
18
Rakefile
|
@ -30,24 +30,6 @@ HERE
|
||||||
end
|
end
|
||||||
=end
|
=end
|
||||||
|
|
||||||
desc "retry dead screenshots"
|
|
||||||
task :retry_dead_screenshots => [:environment] do
|
|
||||||
ds = Sidekiq::DeadSet.new
|
|
||||||
|
|
||||||
ds.select { |job|
|
|
||||||
job.klass == 'ScreenshotWorker'
|
|
||||||
}.map(&:retry)
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "delete dead screenshots"
|
|
||||||
task :delete_dead_screenshots => [:environment] do
|
|
||||||
ds = Sidekiq::DeadSet.new
|
|
||||||
|
|
||||||
ds.select { |job|
|
|
||||||
job.klass == 'ScreenshotWorker'
|
|
||||||
}.map(&:delete)
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "prune logs"
|
desc "prune logs"
|
||||||
task :prune_logs => [:environment] do
|
task :prune_logs => [:environment] do
|
||||||
Stat.prune!
|
Stat.prune!
|
||||||
|
|
|
@ -64,7 +64,11 @@ class LetsEncryptWorker
|
||||||
puts "testing #{challenge_url}"
|
puts "testing #{challenge_url}"
|
||||||
|
|
||||||
begin
|
begin
|
||||||
res = HTTP.timeout(connect: 10, write: 10, read: 10).follow.get(challenge_url)
|
# Some dumb letsencrypt related cert expiration issue hotfix
|
||||||
|
ctx = OpenSSL::SSL::SSLContext.new
|
||||||
|
ctx.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
||||||
|
|
||||||
|
res = HTTP.timeout(connect: 10, write: 10, read: 10).follow.get(challenge_url, ssl_context: ctx)
|
||||||
rescue => e
|
rescue => e
|
||||||
puts e.inspect
|
puts e.inspect
|
||||||
puts "error with #{challenge_url}"
|
puts "error with #{challenge_url}"
|
||||||
|
|
|
@ -6,7 +6,7 @@ class ScreenshotWorker
|
||||||
HARD_TIMEOUT = 30.freeze
|
HARD_TIMEOUT = 30.freeze
|
||||||
PAGE_WAIT_TIME = 5.freeze # 3D/VR sites take a bit to render after loading usually.
|
PAGE_WAIT_TIME = 5.freeze # 3D/VR sites take a bit to render after loading usually.
|
||||||
include Sidekiq::Worker
|
include Sidekiq::Worker
|
||||||
sidekiq_options queue: :screenshots, retry: 2, backtrace: true
|
sidekiq_options queue: :screenshots, retry: 10, backtrace: true
|
||||||
|
|
||||||
def perform(username, path)
|
def perform(username, path)
|
||||||
site = Site[username: username]
|
site = Site[username: username]
|
||||||
|
@ -47,13 +47,15 @@ class ScreenshotWorker
|
||||||
base_image_tmpfile_path = "/tmp/#{SecureRandom.uuid}.png"
|
base_image_tmpfile_path = "/tmp/#{SecureRandom.uuid}.png"
|
||||||
|
|
||||||
http_resp = HTTP.basic_auth(user: api_user, pass: api_password).get(uri)
|
http_resp = HTTP.basic_auth(user: api_user, pass: api_password).get(uri)
|
||||||
BlackBox.new(site, path).check_uri(http_resp.headers['X-URL']) if defined?(BlackBox)
|
BlackBox.new(site, path).check_uri(http_resp.headers['X-URL']) if defined?(BlackBox) && http_resp.headers['X-URL']
|
||||||
File.write base_image_tmpfile_path, http_resp.to_s
|
File.write base_image_tmpfile_path, http_resp.to_s
|
||||||
|
|
||||||
user_screenshots_path = File.join SCREENSHOTS_PATH, Site.sharding_dir(username), username
|
user_screenshots_path = File.join SCREENSHOTS_PATH, Site.sharding_dir(username), username
|
||||||
screenshot_path = File.join user_screenshots_path, File.dirname(path_for_screenshot)
|
screenshot_path = File.join user_screenshots_path, File.dirname(path_for_screenshot)
|
||||||
FileUtils.mkdir_p screenshot_path unless Dir.exist?(screenshot_path)
|
FileUtils.mkdir_p screenshot_path unless Dir.exist?(screenshot_path)
|
||||||
|
|
||||||
|
FileUtils.cp base_image_tmpfile_path, File.join(user_screenshots_path, "#{path_for_screenshot}.png")
|
||||||
|
|
||||||
Site::SCREENSHOT_RESOLUTIONS.each do |res|
|
Site::SCREENSHOT_RESOLUTIONS.each do |res|
|
||||||
width, height = res.split('x').collect {|r| r.to_i}
|
width, height = res.split('x').collect {|r| r.to_i}
|
||||||
|
|
||||||
|
@ -69,6 +71,8 @@ class ScreenshotWorker
|
||||||
end
|
end
|
||||||
|
|
||||||
true
|
true
|
||||||
|
rescue WebP::EncoderError => e
|
||||||
|
puts "Failed: #{username} #{path} #{e.inspect}"
|
||||||
rescue => e
|
rescue => e
|
||||||
raise e
|
raise e
|
||||||
ensure
|
ensure
|
||||||
|
|
|
@ -24,11 +24,20 @@ class ThumbnailWorker
|
||||||
format = File.extname(path).gsub('.', '')
|
format = File.extname(path).gsub('.', '')
|
||||||
full_thumbnail_path = File.join(user_thumbnails_path, "#{path}.#{res}.webp")
|
full_thumbnail_path = File.join(user_thumbnails_path, "#{path}.#{res}.webp")
|
||||||
|
|
||||||
image = Rszr::Image.load site_file_path
|
begin
|
||||||
if image.width > image.height
|
image = Rszr::Image.load site_file_path
|
||||||
image.resize! width, :auto
|
rescue Rszr::LoadError
|
||||||
else
|
next
|
||||||
image.resize! :auto, height
|
end
|
||||||
|
|
||||||
|
begin
|
||||||
|
if image.width > image.height
|
||||||
|
image.resize! width, :auto
|
||||||
|
else
|
||||||
|
image.resize! :auto, height
|
||||||
|
end
|
||||||
|
rescue Rszr::TransformationError
|
||||||
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
begin
|
begin
|
||||||
|
|
Loading…
Add table
Reference in a new issue