influitive / apartment-activejob Goto Github PK
View Code? Open in Web Editor NEWActiveJob support for the Apartment Gem
License: MIT License
ActiveJob support for the Apartment Gem
License: MIT License
I'm looking at using ActiveJob in my app. Is this gem the way to go or should I go with something like the apartment-sidekiq
option instead?
Adding gem 'apartment-activejob'
to Gemfile then bundle
causes:
Could not find gem 'apartment-activejob' in any of the gem sources listed in your Gemfile or available on this machine.
Workaround for now (use github as source):
gem 'apartment-activejob', github: 'influitive/apartment-activejob'
We implemented multitenancy on a medium-large rails 4.2 app using apartment, and used this gem to allow jobs to be executed under the correct tenant. However, After using this for sometime, we are seeing Apartment::TenantNotFound
errors for jobs scheduled in the future which, due to events in the normal application lifecycle, are run when the tenant has been deleted.
Because this gem is implemented to switch tenants before ActiveJob can set up callbacks and error handling, we are not able to handle the error using ActiveJob's built in error handling:
class ApplicationJob < ActiveJob::Base
# Would be ideal but does not work
rescue_from Apartment::TenantNotFound do |e|
# Handle error ...
end
end
Given the nature of jobs, it is expected that some of the data might not be available at the time of running the job. This gem should therefore not assume existence of the tenant when the job is running.
In our application, we are using this hacked version of code pulled out of this gem in the meantime:
module Apartment
module CustomActiveJobExtension
extend ActiveSupport::Concern
class_methods do
def execute(job_data)
Apartment::Tenant.switch(job_data['tenant']) do
super
end
rescue Apartment::TenantNotFound
# our custom error handling ...
end
end
def serialize
super.merge('tenant' => Apartment::Tenant.current)
end
end
end
class ActiveJob::Base
include Apartment::CustomActiveJobExtension
end
It would be better if this were exposed as some kind of configuration; perhaps something like this:
Apartment::ActiveJob.configure do |config|
# Assign handler as any object with a #call method
# Examples:
config.tenant_not_found_error_handler = -> (e) { ExceptionNotifier.notify(e) }
config.tenant_not_found_error_handler = MyCustomErrorHandler.new
end
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.