diff --git a/lib/suspenders.rb b/lib/suspenders.rb index 503486868..f713680d4 100644 --- a/lib/suspenders.rb +++ b/lib/suspenders.rb @@ -1,6 +1,7 @@ require 'suspenders/version' require 'suspenders/generators/app_generator' require "suspenders/generators/enforce_ssl_generator" +require "suspenders/generators/initialize_active_job_generator" require 'suspenders/generators/static_generator' require 'suspenders/generators/stylesheet_base_generator' require 'suspenders/actions' diff --git a/lib/suspenders/generators/app_generator.rb b/lib/suspenders/generators/app_generator.rb index cf1b971f8..79849d27a 100644 --- a/lib/suspenders/generators/app_generator.rb +++ b/lib/suspenders/generators/app_generator.rb @@ -217,6 +217,7 @@ def remove_routes_comment_lines def generate_default run("spring stop") + generate("suspenders:initialize_active_job") generate("suspenders:enforce_ssl") generate("suspenders:static") generate("suspenders:stylesheet_base") diff --git a/lib/suspenders/generators/initialize_active_job_generator.rb b/lib/suspenders/generators/initialize_active_job_generator.rb new file mode 100644 index 000000000..22578b1aa --- /dev/null +++ b/lib/suspenders/generators/initialize_active_job_generator.rb @@ -0,0 +1,19 @@ +require "rails/generators" + +module Suspenders + class InitializeActiveJobGenerator < Rails::Generators::Base + source_root( + File.expand_path( + File.join("..", "..", "..", "templates"), + File.dirname(__FILE__), + ), + ) + + def initialize_active_job + copy_file( + "active_job.rb", + "config/initializers/active_job.rb", + ) + end + end +end diff --git a/spec/features/new_project_spec.rb b/spec/features/new_project_spec.rb index a9203bd57..eebf1278b 100644 --- a/spec/features/new_project_spec.rb +++ b/spec/features/new_project_spec.rb @@ -100,6 +100,11 @@ expect(env).to include "RACK_MINI_PROFILER=0" end + it "initializes ActiveJob to avoid memory bloat" do + expect(File). + to exist("#{project_path}/config/initializers/active_job.rb") + end + it "creates a rack-mini-profiler initializer" do expect(File). to exist("#{project_path}/config/initializers/rack_mini_profiler.rb") diff --git a/templates/active_job.rb b/templates/active_job.rb new file mode 100644 index 000000000..99e1ecfb2 --- /dev/null +++ b/templates/active_job.rb @@ -0,0 +1,13 @@ +require "active_job/logging" + +ActiveSupport::Notifications.unsubscribe("enqueue.active_job") + +module ActiveJob + module Logging + class EnqueueLogSubscriber < LogSubscriber + define_method :enqueue, instance_method(:enqueue) + end + end +end + +ActiveJob::Logging::EnqueueLogSubscriber.attach_to(:active_job)