try new webdav, use remote service for initial site screenshots

This commit is contained in:
Kyle Drake 2016-12-10 19:42:29 -06:00
parent 817012042d
commit fc1afb558a
4 changed files with 22 additions and 40 deletions

View file

@ -20,7 +20,7 @@ gem 'stripe', '1.15.0' #, source: 'https://code.stripe.com/'
gem 'cocaine' gem 'cocaine'
gem 'zipruby' gem 'zipruby'
gem 'sass', require: nil gem 'sass', require: nil
gem 'dav4rack' gem 'dav4rack', git: 'https://github.com/planio-gmbh/dav4rack.git', branch: 'redmine-storage'
gem 'filesize' gem 'filesize'
gem 'thread' gem 'thread'
gem 'scrypt' gem 'scrypt'

View file

@ -1,3 +1,14 @@
GIT
remote: https://github.com/planio-gmbh/dav4rack.git
revision: e68dcf97399a116878a1a68b5c879f5cb05c40cb
branch: redmine-storage
specs:
dav4rack (0.3.0)
nokogiri (>= 1.4.2)
ox (>= 2.1.0)
rack (>= 1.1.0)
uuidtools (~> 2.1.1)
GEM GEM
remote: https://rubygems.org/ remote: https://rubygems.org/
specs: specs:
@ -49,10 +60,6 @@ GEM
safe_yaml (~> 1.0.0) safe_yaml (~> 1.0.0)
crass (1.0.2) crass (1.0.2)
dante (0.2.0) dante (0.2.0)
dav4rack (0.3.0)
nokogiri (>= 1.4.2)
rack (>= 1.1.0)
uuidtools (~> 2.1.1)
docile (1.1.5) docile (1.1.5)
domain_name (0.5.20160826) domain_name (0.5.20160826)
unf (>= 0.0.5, < 1.0.0) unf (>= 0.0.5, < 1.0.0)
@ -126,6 +133,7 @@ GEM
mini_portile2 (~> 2.1.0) mini_portile2 (~> 2.1.0)
nokogumbo (1.4.7) nokogumbo (1.4.7)
nokogiri nokogiri
ox (2.4.6)
paypal-recurring (1.1.0) paypal-recurring (1.1.0)
pg (0.18.4) pg (0.18.4)
poltergeist (1.11.0) poltergeist (1.11.0)
@ -258,7 +266,7 @@ DEPENDENCIES
certified certified
cocaine cocaine
coveralls coveralls
dav4rack dav4rack!
erubis erubis
fabrication fabrication
faker faker

View file

@ -22,6 +22,7 @@ development:
- 10.0.0.2 - 10.0.0.2
education_tag_whitelist: education_tag_whitelist:
- mrteacher - mrteacher
screenshots_url: http://screenshots:derp@127.0.0.1:12345
test: test:
database: 'postgres://localhost/neocities_test' database: 'postgres://localhost/neocities_test'
database_pool: 1 database_pool: 1

View file

@ -7,49 +7,22 @@ require 'open3'
class ScreenshotWorker class ScreenshotWorker
SCREENSHOTS_PATH = Site::SCREENSHOTS_ROOT SCREENSHOTS_PATH = Site::SCREENSHOTS_ROOT
HARD_TIMEOUT = 30.freeze HARD_TIMEOUT = 30.freeze
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: 3, backtrace: true sidekiq_options queue: :screenshots, retry: 3, backtrace: true
def perform(username, path) def perform(username, path)
path = "/#{path}" unless path[0] == '/' path = "/#{path}" unless path[0] == '/'
screenshot = Tempfile.new 'neocities_screenshot'
screenshot.close
screenshot_output_path = screenshot.path+'.png'
line = Cocaine::CommandLine.new( uri = Addressable::URI.parse $config['screenshots_url']
"timeout #{HARD_TIMEOUT} phantomjs #{File.join DIR_ROOT, 'files', 'phantomjs_screenshot.js'}", ":url :output", api_user, api_password = uri.user, uri.password
expected_outcodes: [0] uri = "#{uri.scheme}://#{uri.host}:#{uri.port}" + '?' + Rack::Utils.build_query(
url: Site.select(:username,:domain).where(username: username).first.uri + path,
wait_time: PAGE_WAIT_TIME
) )
begin
output = line.run(
url: "http://#{username}.neocities.org#{path}",
output: screenshot_output_path
)
rescue Cocaine::ExitStatusError => e
raise e
# We set is_crashing after retries now, but use this code to go back to instant:
#if e.message && e.message.match(/returned 124/)
# puts "#{username}/#{path} is timing out, discontinuing"
# site = Site[username: username]
# site.is_crashing = true
# site.save_changes validate: false
# return true
#
#else
# raise
#end
ensure
screenshot.unlink
end
img_list = Magick::ImageList.new img_list = Magick::ImageList.new
img_list.from_blob File.read(screenshot_output_path) img_list.from_blob HTTP.basic_auth(user: api_user, pass: api_password).get(uri).to_s
screenshot.unlink
File.unlink screenshot_output_path
img_list.new_image(img_list.first.columns, img_list.first.rows) { self.background_color = "white" } img_list.new_image(img_list.first.columns, img_list.first.rows) { self.background_color = "white" }
img = img_list.reverse.flatten_images img = img_list.reverse.flatten_images