Skip to content

Commit 6ec498f

Browse files
committed
Guard against missing tenant context in jobs
Fail fast when a job runs without the tenant payload injected by `perform_later`, instead of crashing later on `context["tenant"]`. This makes accidental `perform_now` usage easier to diagnose: > Missing tenant context, use perform_later (via > TenantSwitchEachJob) instead of perform_now Also avoid enqueueing a job from the Postmark inactive-recipient rescue path so suppression sync still works in synchronous flows.
1 parent 4496102 commit 6ec498f

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

app/jobs/concerns/tenant_context.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@ def serialize
1919

2020
def with_context(&block)
2121
context = arguments.pop
22+
raise "Missing tenant context, use perform_later (via TenantSwitchEachJob) instead of perform_now" unless context.is_a?(Hash) && context.key?("tenant")
23+
2224
Tenant.switch(context["tenant"]) do
2325
Current.set(context["current"], &block)
2426
end
2527
ensure
26-
set_context(context)
28+
set_context(context) if context
2729
end
2830

2931
private

app/models/mail_delivery/email.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def process!
3939
mail_delivery.store_preview_from!(message)
4040
end
4141
rescue Postmark::InactiveRecipientError
42-
Scheduled::PostmarkSyncSuppressionsJob.perform_now
42+
EmailSuppression.sync_postmark!(fromdate: 1.week.ago)
4343
suppressed!
4444
mail_delivery.store_preview_from!(message)
4545
rescue Postmark::InvalidEmailRequestError

0 commit comments

Comments
 (0)