Skip to content

Commit

Permalink
mailer worker always runs, but only delivers if email is enabled #2070
Browse files Browse the repository at this point in the history
  • Loading branch information
stuzart committed Nov 21, 2024
1 parent 584c47a commit 7c8c3cb
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
6 changes: 6 additions & 0 deletions app/jobs/enhanced_mail_delivery_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,10 @@ class EnhancedMailDeliveryJob < ActionMailer::MailDeliveryJob
Seek::Config.smtp_propagate
Seek::Config.site_base_host_propagate
end

around_perform do |_job, block|
if Seek::Config.email_enabled
block.call
end
end
end
1 change: 1 addition & 0 deletions app/views/admin/_email.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<%= link_to '#', id: 'queue-test-email-btn', class: 'btn btn-default' do %>
<%= image("test", title: "Send testing email", alt: "Test")%> Queue test email
<% end %>
<p class="help-block">Note that testing the Queue requires settings to be saved first</p>
<div id='ajax_loader_position'></div>
<% end %>
</div>
Expand Down
2 changes: 1 addition & 1 deletion lib/seek/workers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def self.daemonize_commands(commands)
def self.create_commands(action)
commands = []
queues = [QueueNames::DEFAULT]
queues << QueueNames::MAILERS if Seek::Config.email_enabled
queues << QueueNames::MAILERS
queues << QueueNames::AUTH_LOOKUP if Seek::Config.auth_lookup_enabled
queues << QueueNames::REMOTE_CONTENT if Seek::Config.cache_remote_files
queues << QueueNames::SAMPLES if Seek::Config.samples_enabled
Expand Down
16 changes: 16 additions & 0 deletions test/unit/jobs/enhanced_mail_delivery_job_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,20 @@ class EnhancedMailDeliveryJobTest < ActiveSupport::TestCase
assert site_base_host_propagate_called
end
end

test 'perform with email disabled' do
with_config_value(:email_enabled, true) do
assert_enqueued_jobs(1, only: EnhancedMailDeliveryJob, queue: QueueNames::MAILERS) do
Mailer.test_email('[email protected]').deliver_later
end
end

with_config_value(:email_enabled, false) do
assert_emails 0 do
assert_performed_jobs(1, only: EnhancedMailDeliveryJob) do
Mailer.test_email('[email protected]').deliver_later
end
end
end
end
end

0 comments on commit 7c8c3cb

Please sign in to comment.