Module: DispatchPolicy
- Defined in:
- lib/dispatch_policy.rb,
lib/dispatch_policy/gate.rb,
lib/dispatch_policy/tick.rb,
lib/dispatch_policy/assets.rb,
lib/dispatch_policy/bypass.rb,
lib/dispatch_policy/config.rb,
lib/dispatch_policy/engine.rb,
lib/dispatch_policy/policy.rb,
lib/dispatch_policy/context.rb,
lib/dispatch_policy/railtie.rb,
lib/dispatch_policy/version.rb,
lib/dispatch_policy/decision.rb,
lib/dispatch_policy/pipeline.rb,
lib/dispatch_policy/registry.rb,
lib/dispatch_policy/forwarder.rb,
lib/dispatch_policy/tick_loop.rb,
lib/dispatch_policy/policy_dsl.rb,
lib/dispatch_policy/repository.rb,
lib/dispatch_policy/serializer.rb,
lib/dispatch_policy/job_extension.rb,
lib/dispatch_policy/gates/throttle.rb,
lib/dispatch_policy/operator_hints.rb,
app/models/dispatch_policy/partition.rb,
lib/dispatch_policy/inflight_tracker.rb,
app/models/dispatch_policy/staged_job.rb,
lib/dispatch_policy/cursor_pagination.rb,
lib/dispatch_policy/gates/concurrency.rb,
app/models/dispatch_policy/tick_sample.rb,
app/models/dispatch_policy/inflight_job.rb,
app/models/dispatch_policy/application_record.rb,
lib/dispatch_policy/gates/adaptive_concurrency.rb,
app/controllers/dispatch_policy/assets_controller.rb,
app/controllers/dispatch_policy/policies_controller.rb,
app/controllers/dispatch_policy/dashboard_controller.rb,
app/controllers/dispatch_policy/partitions_controller.rb,
app/models/dispatch_policy/adaptive_concurrency_stats.rb,
app/controllers/dispatch_policy/application_controller.rb,
app/controllers/dispatch_policy/staged_jobs_controller.rb,
lib/generators/dispatch_policy/install/install_generator.rb
Defined Under Namespace
Modules: Assets, Bypass, CursorPagination, Forwarder, Gates, Generators, InflightTracker, JobExtension, OperatorHints, Repository, Serializer, TickLoop
Classes: AdaptiveConcurrencyStats, ApplicationController, ApplicationRecord, AssetsController, Config, Context, DashboardController, Decision, Engine, EnqueueFailed, Error, Gate, InflightJob, InvalidPolicy, Partition, PartitionsController, Pipeline, PoliciesController, Policy, PolicyAlreadyRegistered, PolicyDSL, Railtie, Registry, StagedJob, StagedJobsController, Tick, TickSample, UnknownGate
Constant Summary
collapse
- PG_BACKED_ADAPTER_HINTS =
Adapters whose enqueue runs against ActiveRecord::Base.connection (so the adapter INSERT can join the admission TX) or whose semantics make atomicity moot (test/inline). Substring match against the adapter class name keeps the check resilient to ActiveJob’s wrapper renames.
%w[GoodJob SolidQueue].freeze
- EXEMPT_ADAPTER_HINTS =
%w[Test Inline Async].freeze
- VERSION =
"0.4.0"
Class Method Summary
collapse
Class Method Details
.config ⇒ Object
51
52
53
|
# File 'lib/dispatch_policy.rb', line 51
def config
@config ||= Config.new
end
|
47
48
49
|
# File 'lib/dispatch_policy.rb', line 47
def configure
yield config
end
|
.registry ⇒ Object
59
60
61
|
# File 'lib/dispatch_policy.rb', line 59
def registry
@registry ||= Registry.new
end
|
.reset_config! ⇒ Object
55
56
57
|
# File 'lib/dispatch_policy.rb', line 55
def reset_config!
@config = Config.new
end
|
.reset_registry! ⇒ Object
63
64
65
|
# File 'lib/dispatch_policy.rb', line 63
def reset_registry!
@registry = Registry.new
end
|
.warn_unsupported_adapter ⇒ Object
Logs a warning if the configured ActiveJob adapter is not one of the PG-backed ones the gem can guarantee atomic admission for. We do NOT raise: a host may use a custom PG-backed adapter we don’t recognize, or may have accepted the trade-off knowingly. The warning is enough to surface the issue at boot.
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/dispatch_policy.rb', line 72
def warn_unsupported_adapter
return unless defined?(::ActiveJob::Base)
adapter = ::ActiveJob::Base.queue_adapter
return unless adapter
klass_name = adapter.class.name.to_s
return if (PG_BACKED_ADAPTER_HINTS + EXEMPT_ADAPTER_HINTS).any? { |hint| klass_name.include?(hint) }
config.logger&.warn(
"[dispatch_policy] active_job adapter is #{klass_name}; atomic admission requires " \
"a PG-backed adapter that shares ActiveRecord::Base's connection (good_job, solid_queue). " \
"If the worker process crashes between admission COMMIT and adapter enqueue, the job is lost. " \
"Set DispatchPolicy.config.database_role if you use a separate DB role for queueing."
)
end
|