Sha256: ca088e2e6a3f40324cf1c53f4867502e0af75e4672a56104770454635248c126

Contents?: true

Size: 802 Bytes

Versions: 14

Compression:

Stored size: 802 Bytes

Contents

require 'apartment/delayed_job/enqueue'

module Apartment
  module Delayed
    module Job

      # Before and after hooks for performing Delayed Jobs within a particular apartment database
      # Include these in your delayed jobs models and make sure provide a @database attr that will be serialized by DJ
      # Note also that any models that are being serialized need the Apartment::Delayed::Requirements module mixed in to it
      module Hooks

        attr_accessor :database

        def before(job)
          @_current_database = Apartment::Database.current_database
          Apartment::Database.switch(job.payload_object.database) if job.payload_object.database
        end

        def after
          Apartment::Database.switch(@_current_database)
        end

      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
apartment-0.22.1 lib/apartment/delayed_job/hooks.rb
apartment-0.22.0 lib/apartment/delayed_job/hooks.rb
apartment-0.21.1 lib/apartment/delayed_job/hooks.rb
apartment-0.21.0 lib/apartment/delayed_job/hooks.rb
apartment-0.20.0 lib/apartment/delayed_job/hooks.rb
apartment-0.19.0 lib/apartment/delayed_job/hooks.rb
apartment-0.18.0 lib/apartment/delayed_job/hooks.rb
apartment-0.17.3 lib/apartment/delayed_job/hooks.rb
apartment-0.17.2 lib/apartment/delayed_job/hooks.rb
apartment-0.17.1 lib/apartment/delayed_job/hooks.rb
apartment-0.17.0 lib/apartment/delayed_job/hooks.rb
apartment-0.16.0 lib/apartment/delayed_job/hooks.rb
apartment-0.15.0 lib/apartment/delayed_job/hooks.rb
apartment-0.14.4 lib/apartment/delayed_job/hooks.rb