From 6e009f16b9c7d94eb7ba10746ccaec1fa41bed4f Mon Sep 17 00:00:00 2001 From: Adam Cooke Date: Fri, 2 Jun 2017 15:29:54 +0100 Subject: [PATCH] use explicit autoloads rather than from paths --- Procfile | 2 +- config/application.rb | 2 +- config/initializers/postal.rb | 2 +- lib/postal.rb | 42 +++++++++++++++++++++++++++++++++++ lib/postal/fast_server.rb | 12 ++++++++++ lib/postal/message_db.rb | 18 +++++++++++++++ lib/postal/smtp_server.rb | 9 ++++++++ lib/tasks/postal.rake | 5 ----- script/worker.rb | 3 +++ 9 files changed, 87 insertions(+), 8 deletions(-) create mode 100644 lib/postal.rb create mode 100644 lib/postal/fast_server.rb create mode 100644 lib/postal/message_db.rb create mode 100644 lib/postal/smtp_server.rb create mode 100644 script/worker.rb diff --git a/Procfile b/Procfile index 7998818..7d9514d 100644 --- a/Procfile +++ b/Procfile @@ -1,6 +1,6 @@ web: bundle exec puma -C config/puma.rb fast: bundle exec rake postal:fast_server -worker: bundle exec rake postal:worker +worker: bundle exec ruby script/worker.rb cron: bundle exec rake postal:cron smtp: bundle exec rake postal:smtp_server requeuer: bundle exec rake postal:requeuer diff --git a/config/application.rb b/config/application.rb index a99280e..f49c023 100644 --- a/config/application.rb +++ b/config/application.rb @@ -27,7 +27,7 @@ module Postal end # Include from lib - config.eager_load_paths += %W(#{config.root}/lib #{config.root}/app/jobs) + config.eager_load_namespaces << Postal # Disable field_with_errors config.action_view.field_error_proc = Proc.new { |t, i| t } diff --git a/config/initializers/postal.rb b/config/initializers/postal.rb index ed04aed..78a0487 100644 --- a/config/initializers/postal.rb +++ b/config/initializers/postal.rb @@ -1,2 +1,2 @@ -require 'postal/error' +require 'postal' require 'postal/message_db/mysql' diff --git a/lib/postal.rb b/lib/postal.rb new file mode 100644 index 0000000..1ddab62 --- /dev/null +++ b/lib/postal.rb @@ -0,0 +1,42 @@ +module Postal + + extend ActiveSupport::Autoload + + eager_autoload do + autoload :AppLogger + autoload :BounceMessage + autoload :Config + autoload :Countries + autoload :DKIMHeader + autoload :Error + autoload :FastServer + autoload :Helpers + autoload :HTTP + autoload :HTTPSender + autoload :Job + autoload :LetsEncrypt + autoload :MessageDB + autoload :MessageInspection + autoload :MessageParser + autoload :MessageRequeuer + autoload :QueryString + autoload :RabbitMQ + autoload :ReplySeparator + autoload :RspecHelpers + autoload :SendResult + autoload :Sender + autoload :SMTPServer + autoload :SpamCheck + autoload :UserCreator + autoload :Version + autoload :Worker + end + + def self.eager_load! + super + Postal::MessageDB.eager_load! + Postal::FastServer.eager_load! + Postal::SMTPServer.eager_load! + end + +end diff --git a/lib/postal/fast_server.rb b/lib/postal/fast_server.rb new file mode 100644 index 0000000..e4c63bc --- /dev/null +++ b/lib/postal/fast_server.rb @@ -0,0 +1,12 @@ +module Postal + module FastServer + extend ActiveSupport::Autoload + eager_autoload do + autoload :Client + autoload :HTTPHeader + autoload :HTTPHeaderSet + autoload :Interface + autoload :Server + end + end +end diff --git a/lib/postal/message_db.rb b/lib/postal/message_db.rb new file mode 100644 index 0000000..2d422d0 --- /dev/null +++ b/lib/postal/message_db.rb @@ -0,0 +1,18 @@ +module Postal + module MessageDB + extend ActiveSupport::Autoload + eager_autoload do + autoload :Click + autoload :Database + autoload :Delivery + autoload :LiveStats + autoload :Load + autoload :Message + autoload :Migration + autoload :Provisioner + autoload :Statistics + autoload :SuppressionList + autoload :Webhooks + end + end +end diff --git a/lib/postal/smtp_server.rb b/lib/postal/smtp_server.rb new file mode 100644 index 0000000..9755e39 --- /dev/null +++ b/lib/postal/smtp_server.rb @@ -0,0 +1,9 @@ +module Postal + module SMTPServer + extend ActiveSupport::Autoload + eager_autoload do + autoload :Client + autoload :Server + end + end +end diff --git a/lib/tasks/postal.rake b/lib/tasks/postal.rake index 4e4c756..869e3c2 100644 --- a/lib/tasks/postal.rake +++ b/lib/tasks/postal.rake @@ -1,10 +1,5 @@ namespace :postal do - desc "Start the backend job worker" - task :worker => :environment do - Postal::Worker.new([:main]).work - end - desc "Start the cron worker" task :cron => :environment do require 'clockwork' diff --git a/script/worker.rb b/script/worker.rb new file mode 100644 index 0000000..85ba7e1 --- /dev/null +++ b/script/worker.rb @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +require_relative '../config/environment' +Postal::Worker.new([:main]).work