bin/httpthumbnailer in httpthumbnailer-1.2.0 vs bin/httpthumbnailer in httpthumbnailer-1.3.0

- old
+ new

@@ -11,12 +11,22 @@ description: 'print backend versions and supported formats' option :limit_disk, cast: Integer, description: 'image cache temporary file size limit in MiB', default: 1024 + options :plugins, + cast: Pathname, + description: 'path to directory from which plugins will be loaded (files with .rb extension)', + default: '/usr/share/httpthumbnailer/plugins' switch :no_optimization, - description: 'disable load time size hinting and prescaling optimizations' + description: 'disable load time size hinting and downsampling optimizations all together' + switch :reload, + description: 'reload input images without size hint that got upscaled instead of downsampling (broken JPEG lib)' + switch :no_upscale_fix, + description: 'do nothing if image got upscaled when using size hint (broken JPEG lib)' + switch :no_downsample, + description: 'disable downsampling of input image before processing' version (Pathname.new(__FILE__).dirname + '..' + 'VERSION').read end settings do |settings| if settings.formats @@ -35,39 +45,57 @@ puts "\t#{Magick::InterlaceType.values.map(&:to_s).join(' ')}" exit 0 end Controller.settings[:optimization] = (not settings.no_optimization) + Controller.settings[:reload] = settings.reload + Controller.settings[:no_upscale_fix] = settings.no_upscale_fix + Controller.settings[:no_downsample] = settings.no_downsample Controller.settings[:limit_memory] = settings.limit_memory * 1024**2 Controller.settings[:limit_map] = settings.limit_disk * 1024**2 Controller.settings[:limit_disk] = settings.limit_disk * 1024**2 end main do |settings| require 'httpthumbnailer/error_reporter' require 'httpthumbnailer/thumbnailer' - class HTTPThumbniler < Controller + settings.plugins.map do |dir| + begin + dir.realpath + rescue Errno::ENOENT => error + log.warn "plugin directory '#{dir}' is not accessible: #{error}" + nil + end + end.compact.map do |dir| + Pathname::glob(dir + '**/*.rb') + end.each do |plugin_files| + plugin_files.sort.each do |plugin_file| + Plugin::Thumbnailer.setup_plugin_from_file(plugin_file) + end + end + + class HTTPThumbnailer < Controller extend Stats def_stats( :workers, :total_requests, :total_errors ) raindrops_stats = Raindrops::Middleware::Stats.new self.use Raindrops::Middleware, stats: raindrops_stats - StatsReporter << HTTPThumbniler.stats + StatsReporter << HTTPThumbnailer.stats StatsReporter << raindrops_stats StatsReporter << Plugin::Thumbnailer::Service.stats StatsReporter << Plugin::ResponseHelpers.stats self.define do - HTTPThumbniler.stats.incr_total_requests + HTTPThumbnailer.stats.incr_total_requests on error? do - HTTPThumbniler.stats.incr_total_errors + HTTPThumbnailer.stats.incr_total_errors run ErrorReporter end on 'stats' do run StatsReporter @@ -85,13 +113,13 @@ run Thumbnailer end end end - HTTPThumbniler + HTTPThumbnailer end after_fork do |server, worker| - HTTPThumbniler.stats.incr_workers + HTTPThumbnailer.stats.incr_workers end end