Git Product home page Git Product logo

apartment-activejob's People

Contributors

bradrobertson avatar desheikh avatar dgroulx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

apartment-activejob's Issues

Gem not found in RubyGems

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'

No way to Handle Apartment::TenantNotFound errors

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.