acts_as_tenant 2.2.2 → 2.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7c0fbfe96e632768ed0f7dfae94d955c791c6ce1b724ef84e0ce6c2ca0fe0d88
4
- data.tar.gz: 4294ce8d41e28d09c730f28ef22d2a28aa59ac1a4d4aba8e0b12ea3dea410719
3
+ metadata.gz: 53bee4c397c092c403da3a466d408aa2df9c7dca123dee7b77c479b99c562f18
4
+ data.tar.gz: 0371d342b53123379832d0a612dbd4e957ff2b7af967b658de9911e852659587
5
5
  SHA512:
6
- metadata.gz: 4c41db14ddabafb233b66c0ac39d2fddd4fb03742ed874ca8a8027e3b46927f70e7eef1d2e65b157073e02b79de95f492859449cc6cd45c828cd4590463191b5
7
- data.tar.gz: 3e9f92da5f007404e79e0381a8a065f04515b5d96f451ce1d91636a8d2c37bac71a0944d2404d53fde07f01e98b26f194317e5be9fbaf66aac9fc155c4ef4ae6
6
+ metadata.gz: dd9d0883f7a764f9b6c6b917b5b1a1fef68b847ed0afe19389ae776eed8fa5ba3ee26df9a6d0e31df7d08e0b81dd75311d2ab92e43c4a08333856a15ec0e0ce6
7
+ data.tar.gz: c92740f25cb15fd95a4adb313dd2e8be5708375dd40159d9421ff0660184f6808bb5173b80d05fbe4211d6aafebbf5999c26700e984567467df3c08bc4b50ad0
data/README.md CHANGED
@@ -451,6 +451,13 @@ Background Processing libraries
451
451
  ActsAsTenant supports
452
452
 
453
453
  - ActiveJob - ActsAsTenant will automatically save the current tenant in ActiveJob arguments and set it when the job runs.
454
+ A job whose tenant was deleted before it ran raises `ActsAsTenant::Errors::TenantNotFound`, an `ActiveJob::DeserializationError`. `discard_on ActiveJob::DeserializationError` drops it along with jobs whose arguments were deleted, and `discard_on ActsAsTenant::Errors::TenantNotFound` drops only those:
455
+
456
+ ```ruby
457
+ class ApplicationJob < ActiveJob::Base
458
+ discard_on ActsAsTenant::Errors::TenantNotFound
459
+ end
460
+ ```
454
461
 
455
462
  - [Sidekiq](//sidekiq.org/)
456
463
  Add the following code to `config/initializers/acts_as_tenant.rb`:
@@ -1,4 +1,11 @@
1
1
  module ActsAsTenant
2
+ module Errors
3
+ # Raised when a job runs after its tenant was deleted. Defined here rather than in errors.rb
4
+ # because it subclasses an ActiveJob error, and this file loads only once ActiveJob does.
5
+ class TenantNotFound < ActiveJob::DeserializationError
6
+ end
7
+ end
8
+
2
9
  module ActiveJobExtensions
3
10
  def self.prepended(base)
4
11
  # Resolve the tenant inside the perform callbacks so `rescue_from`, `retry_on`
@@ -34,8 +41,16 @@ module ActsAsTenant
34
41
  def deserialize_arguments_if_needed
35
42
  return super unless @acts_as_tenant_global_id
36
43
 
37
- @acts_as_tenant_job_tenant = GlobalID::Locator.locate(@acts_as_tenant_global_id)
44
+ @acts_as_tenant_job_tenant = locate_tenant
38
45
  ActsAsTenant.with_tenant(@acts_as_tenant_job_tenant) { super }
39
46
  end
47
+
48
+ # Raise for a deleted tenant as Rails does for a deleted argument. The error's cause is the
49
+ # ActiveRecord::RecordNotFound, so `discard_on ActiveRecord::RecordNotFound` still matches.
50
+ def locate_tenant
51
+ GlobalID::Locator.locate(@acts_as_tenant_global_id)
52
+ rescue ActiveRecord::RecordNotFound
53
+ raise Errors::TenantNotFound
54
+ end
40
55
  end
41
56
  end
@@ -23,7 +23,10 @@ module ActsAsTenant::Sidekiq
23
23
  include Sidekiq::ServerMiddleware if sidekiq_7_and_up?
24
24
 
25
25
  def call(worker_class, msg, queue)
26
- if msg.has_key?("acts_as_tenant")
26
+ # An ActiveJob job carries its own tenant and sets it while it performs (see
27
+ # ActsAsTenant::ActiveJobExtensions), where `discard_on` can handle a tenant that no
28
+ # longer exists. Looking it up here would raise before the job could.
29
+ if msg.has_key?("acts_as_tenant") && !msg.has_key?("wrapped")
27
30
  klass = msg["acts_as_tenant"]["class"].constantize
28
31
  id = msg["acts_as_tenant"]["id"]
29
32
  account = klass.class_eval(&ActsAsTenant.configuration.job_scope).find(id)
@@ -1,3 +1,3 @@
1
1
  module ActsAsTenant
2
- VERSION = "2.2.2"
2
+ VERSION = "2.3.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_tenant
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.2
4
+ version: 2.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erwin Matthijssen