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 +4 -4
- data/README.md +7 -0
- data/lib/acts_as_tenant/active_job_extensions.rb +16 -1
- data/lib/acts_as_tenant/sidekiq.rb +4 -1
- data/lib/acts_as_tenant/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 53bee4c397c092c403da3a466d408aa2df9c7dca123dee7b77c479b99c562f18
|
|
4
|
+
data.tar.gz: 0371d342b53123379832d0a612dbd4e957ff2b7af967b658de9911e852659587
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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 =
|
|
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
|
-
|
|
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)
|