Module: TalkToYourApp::Plugins::Jobs
- Defined in:
- lib/talk_to_your_app/plugins/jobs/plugin.rb,
lib/talk_to_your_app/plugins/jobs/interface.rb,
lib/talk_to_your_app/plugins/jobs/tools/base.rb,
lib/talk_to_your_app/plugins/jobs/adapters/sidekiq.rb,
lib/talk_to_your_app/plugins/jobs/tools/failed_jobs.rb,
lib/talk_to_your_app/plugins/jobs/tools/queue_sizes.rb,
lib/talk_to_your_app/plugins/jobs/tools/recent_jobs.rb,
lib/talk_to_your_app/plugins/jobs/tools/rate_metrics.rb,
lib/talk_to_your_app/plugins/jobs/adapters/solid_queue.rb
Overview
Background-job metrics, exposed as one plugin per backend: :sidekiq and
:solid_queue. Each is enabled independently
(config.plugin :sidekiq, connection: false) and exposes adapter-namespaced
tools (sidekiq.queue_sizes, solid_queue.queue_sizes, …), so both can run
at once — e.g. while migrating from one backend to the other. The job
backends read Redis / their own tables, not a wired SQL connection, so they
are enabled with connection: false.
Defined Under Namespace
Modules: Adapters, Interface, Tools Classes: SidekiqPlugin, SolidQueuePlugin
Constant Summary collapse
- TOOL_TEMPLATES =
The four metric tools, by MCP-name suffix. Each adapter plugin builds its own concrete subclasses bound to its adapter.
{ "queue_sizes" => Tools::QueueSizes, "recent_jobs" => Tools::RecentJobs, "failed_jobs" => Tools::FailedJobs, "rate_metrics" => Tools::RateMetrics, }.freeze
Class Method Summary collapse
- .adapter_for(name) ⇒ Object
-
.build_tools(adapter_name) ⇒ Object
Builds the four metric tools for an adapter, named "
. " and bound to the adapter so each plugin's tools target its own backend. - .known_adapter_names ⇒ Object
-
.register_adapter(name, adapter_class) ⇒ Object
Registers an adapter class under a name.
-
.validate_adapter!(adapter_name) ⇒ Object
Boot validation shared by both adapter plugins: the adapter's backing gem must be loadable and it must implement the full metrics interface.
Class Method Details
.adapter_for(name) ⇒ Object
38 39 40 |
# File 'lib/talk_to_your_app/plugins/jobs/plugin.rb', line 38 def adapter_for(name) @adapters[name&.to_sym] end |
.build_tools(adapter_name) ⇒ Object
Builds the four metric tools for an adapter, named "
48 49 50 51 52 53 54 55 |
# File 'lib/talk_to_your_app/plugins/jobs/plugin.rb', line 48 def build_tools(adapter_name) TOOL_TEMPLATES.map do |suffix, template| Class.new(template) do name "#{adapter_name}.#{suffix}" self.adapter_name = adapter_name end end end |
.known_adapter_names ⇒ Object
42 43 44 |
# File 'lib/talk_to_your_app/plugins/jobs/plugin.rb', line 42 def known_adapter_names @adapters.keys end |
.register_adapter(name, adapter_class) ⇒ Object
Registers an adapter class under a name. The class duck-types
Jobs::Interface and exposes required_gem ({ const:, gem_name: }).
34 35 36 |
# File 'lib/talk_to_your_app/plugins/jobs/plugin.rb', line 34 def register_adapter(name, adapter_class) @adapters[name.to_sym] = adapter_class end |
.validate_adapter!(adapter_name) ⇒ Object
Boot validation shared by both adapter plugins: the adapter's backing gem must be loadable and it must implement the full metrics interface.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/talk_to_your_app/plugins/jobs/plugin.rb', line 59 def validate_adapter!(adapter_name) adapter = adapter_for(adapter_name) unless adapter raise ConfigurationError, "talk_to_your_app: jobs adapter #{adapter_name.inspect} is not registered " \ "(available: #{known_adapter_names.inspect})." end req = adapter.required_gem if req && !Object.const_defined?(req[:const]) raise ConfigurationError, "talk_to_your_app: the #{adapter_name} plugin requires the `#{req[:gem_name]}` gem " \ "(constant #{req[:const]} is not defined)." end unless Interface.satisfied_by?(adapter) raise ConfigurationError, "talk_to_your_app: jobs adapter #{adapter_name.inspect} does not implement the full interface " \ "(#{Interface::METHODS.join(", ")})." end end |