Set ActiveJob configs and convert WelcomeEnterpriseJob to new format

This needs to be done for all jobs.

Docs: https://guides.rubyonrails.org/v4.2/active_job_basics.html
This commit is contained in:
Matt-Yorkley
2020-11-04 17:33:34 +00:00
parent 54a4952dc5
commit 58350ed338
5 changed files with 8 additions and 4 deletions

View File

@@ -1,5 +1,5 @@
WelcomeEnterpriseJob = Struct.new(:enterprise_id) do
def perform
class WelcomeEnterpriseJob < ActiveJob::Base
def perform(enterprise_id)
enterprise = Enterprise.find enterprise_id
EnterpriseMailer.welcome(enterprise).deliver
end

View File

@@ -400,7 +400,7 @@ class Enterprise < ActiveRecord::Base
end
def send_welcome_email
Delayed::Job.enqueue WelcomeEnterpriseJob.new(id)
WelcomeEnterpriseJob.perform_later(id)
end
def strip_url(url)

View File

@@ -199,5 +199,7 @@ module Openfoodnetwork
config.assets.precompile += ['*.jpg', '*.jpeg', '*.png', '*.gif' '*.svg']
config.active_support.escape_html_entities_in_json = true
config.active_job.queue_adapter = :delayed_job
end
end

View File

@@ -51,6 +51,8 @@ Openfoodnetwork::Application.configure do
require 'open_food_network/rack_request_blocker'
# Make sure the middleware is inserted first in middleware chain
config.middleware.insert_before('ActionDispatch::Static', 'RackRequestBlocker')
config.active_job.queue_adapter = :test
end
# Allows us to use _url helpers in Rspec

View File

@@ -8,6 +8,6 @@ describe WelcomeEnterpriseJob do
expect(EnterpriseMailer).to receive(:welcome).with(enterprise).and_return(mail)
expect(mail).to receive(:deliver)
run_job WelcomeEnterpriseJob.new(enterprise.id)
WelcomeEnterpriseJob.perform_now(enterprise.id)
end
end