Module: Axn::Async::Ownership
- Included in:
- Axn::Async
- Defined in:
- lib/axn/async/ownership.rb
Overview
Public predicate for "is this job/notice signal Axn-owned?".
Error-reporter before_notify-style filters (Honeybadger, Sentry, etc.) need to suppress
backend-native duplicate reports for Axn async failures, since Axn already reports them via
its own on_exception path. Doing so means answering "did this notice come from an Axn
action?" — which requires knowing Axn's internal async wiring (the generic Sidekiq worker,
the ActiveJob proxy naming convention, the Sidekiq display_class wire detail).
That knowledge lives here, not in every downstream filter, so a future adapter refactor (a new backend, a worker rename) is a one-line change in Axn instead of a silent break in every downstream integration. See docs/recipes/suppressing-duplicate-async-reports.md.
Constant Summary collapse
- ACTIVE_JOB_PROXY_SUFFIX =
The ActiveJob adapter names its per-action proxy "
::ActiveJobProxy" (see Adapters::ActiveJob). The proxy itself is not < Axn, so we strip the suffix to recover the real action class before constantizing. "::ActiveJobProxy"
Instance Method Summary collapse
-
#owns?(candidate) ⇒ Boolean
Is this job/notice signal Axn-owned?.
-
#register_ownership_predicate {|klass| ... } ⇒ self
Register an additional predicate that recognizes an adapter's own wrapper/worker class as Axn-owned.
Instance Method Details
#owns?(candidate) ⇒ Boolean
Is this job/notice signal Axn-owned?
Accepts whatever an error reporter's Sidekiq/ActiveJob plugin might hand you:
- a Class/Module already resolved by the caller
- a String class name (may carry an "::ActiveJobProxy" suffix from the ActiveJob adapter)
- a Hash (raw Sidekiq job hash, string OR symbol keys) — checks "display_class", then
"wrapped", then "class", in that priority, to recover the real job/action class name
Blank/nil/unrecognized input returns false (never raises), so a filter can pass every signal it has through this predicate without guarding each one.
35 36 37 38 39 40 41 |
# File 'lib/axn/async/ownership.rb', line 35 def owns?(candidate) klass = _ownership_resolve_class(candidate) return false unless klass.is_a?(Module) return true if klass < Axn _ownership_predicates.any? { |predicate| predicate.call(klass) } end |
#register_ownership_predicate {|klass| ... } ⇒ self
Register an additional predicate that recognizes an adapter's own wrapper/worker class as Axn-owned. Lets a new async adapter extend detection without any downstream filter change. The block receives a resolved Class and returns truthy when it is that adapter's wrapper.
49 50 51 52 |
# File 'lib/axn/async/ownership.rb', line 49 def register_ownership_predicate(&block) _ownership_predicates << block self end |