lib/jt-rails-toolbox.rb in jt-rails-toolbox-2.4.2 vs lib/jt-rails-toolbox.rb in jt-rails-toolbox-2.4.3

- old
+ new

@@ -1,22 +1,17 @@ require 'dotenv/rails-now' require 'http_accept_language' require 'paperclip' -require 'sidekiq' require 'validates_email_format_of' require 'validates_phone_format_of' require 'rails_i18n' require 'jt-rails-meta' require 'jt-rails-generator-user' require 'jt-rails-tokenizable' require 'yaml' -# Don't move this require -require 'airbrake' -require 'airbrake/sidekiq/error_handler' - module JTRailsToolbox class Engine < ::Rails::Engine initializer "jt-rails-toolbox" do |app| @@ -28,14 +23,14 @@ @params = yaml[Rails.env.to_s] || {} end end process_params + configure_sidekiq(app) configure_exception_notification(app) configure_mail(app) configure_paperclip(app) - configure_sidekiq(app) end def process_params @params['files'] ||= {} if @params['files']['folder'].nil? @@ -66,19 +61,23 @@ @params['hosts']['cdn_host'] ||= @params['hosts']['asset_host'] # Should avoid namespace with Redis # http://www.mikeperham.com/2015/09/24/storing-data-with-redis/ @params['sidekiq'] ||= {} + @params['sidekiq']['disable'] ||= false @params['sidekiq']['redis_url'] ||= "redis://localhost:6379/0" @params['sidekiq']['namespace'] ||= "#{Rails.application.class.parent_name.parameterize}#{Rails.env.production? ? '' : "-#{Rails.env.to_s}"}" end def configure_exception_notification(app) return if @params['exception'].nil? if @params['exception']['airbrake'] + require 'airbrake' + require 'airbrake/sidekiq/error_handler' unless sidekiq_disabled? + Airbrake.configure do |c| if @params['exception']['airbrake']['host'] c.host = @params['exception']['airbrake']['host'] end @@ -107,11 +106,11 @@ end end require 'exception_notification' require 'exception_notification/rails' - require 'exception_notification/sidekiq' + require 'exception_notification/sidekiq' unless sidekiq_disabled? ExceptionNotification.configure do |config| config.ignored_exceptions += %w{ActionController::InvalidCrossOriginRequest ActionController::InvalidAuthenticityToken} if @params['exception']['slack'] @@ -140,11 +139,11 @@ def configure_paperclip(app) # Strip meta data from images Paperclip::Attachment.default_options[:convert_options] = { all: '-strip' } - # Params in url are bad for SEO, it's better to use fingerprint for having a unique url + # Params in url are bad for SEO, it's better to use fingerprint for having an unique url Paperclip::Attachment.default_options[:use_timestamp] = false path = "#{@params['files']['folder']}/:class/:attachment/:id/:style/:fingerprint.:content_type_extension" Paperclip::Attachment.default_options[:path] = ":rails_root/public/#{path}" @@ -153,18 +152,26 @@ ActionController::Base.asset_host = @params['hosts']['asset_host'] app.config.action_controller.asset_host = @params['hosts']['asset_host'] end def configure_sidekiq(app) + return if sidekiq_disabled? + + require 'sidekiq' + Sidekiq.configure_server do |config| config.redis = { url: @params['sidekiq']['redis_url'], namespace: @params['sidekiq']['namespace'] } end Sidekiq.configure_client do |config| config.redis = { url: @params['sidekiq']['redis_url'], namespace: @params['sidekiq']['namespace'] } end ActiveJob::Base.queue_adapter = :sidekiq + end + + def sidekiq_disabled? + @params['sidekiq']['disable'] == true end end end \ No newline at end of file