-
Notifications
You must be signed in to change notification settings - Fork 110
Open
Description
Hi,
First, thanks you for your work!
I’m running into an issue that causes mission_control-jobs to fail in a multi-tenant app.
My multi-tenant setup is custom-made, but I’m quite sure the problem would also occur with a gem like acts_as_tenant, since it uses the same pattern to set the current tenant in a job.
Chronology to trigger the problem:
- access
/jobs/applications/ubikly/finished/jobs ActiveJob::JobProxyis initialized somewhere and callsdeserialize- if the tenant is nil,
Current#resetis called and the lineI18n.default_locale = Rails.application.config.i18n.default_localefailed with the following error :I18n::InvalidLocale at /applications/ubikly/finished/jobs :"en-US" is not a valid locale
It seems that at the moment when default_locale is being set, :"en-US" is not yet available, so the error is raised. However, in my debug console, I18n.available_locale?(:"en-US") returns true.
It seems linked to issues #229 and #244.
config/initializers/i18n.rb:
Rails.application.configure do
config.i18n.default_locale = :"en-US"
config.i18n.available_locales = %i[en-GB en-US es-ES es-MX fr-FR fr-CH fr-CA]
endapp/models/current.rb:
# frozen_string_literal: true
class Current < ActiveSupport::CurrentAttributes
attribute :tenant
resets do
I18n.default_locale = Rails.application.config.i18n.default_locale # => error is raised from here
end
def tenant=(tenant)
super
if tenant.nil?
reset
return
end
I18n.default_locale = tenant.default_locale
end
endactive_job_extensions.rb:
# frozen_string_literal: true
module ActiveJobExtensions
def serialize
super.merge("current_tenant" => Current.tenant&.to_global_id&.to_s)
end
def deserialize(job_data)
tenant_global_id = job_data["current_tenant"]
tenant = tenant_global_id ? GlobalID::Locator.locate(tenant_global_id) : nil
Current.tenant = tenant
super
end
endconfig/initializers/active_job.rb:
# frozen_string_literal: true
ActiveSupport.on_load(:active_job) do |base|
base.prepend ActiveJobExtensions
endruby & gems :
- rails 8.0.2
- ruby 3.4.5
- solid_queue 1.2.1
- mission_control-jobs 1.1.0
Metadata
Metadata
Assignees
Labels
No labels