Module: Wurk::Web::Enterprise::Limits
- Defined in:
- lib/wurk/web/enterprise.rb
Overview
Limits tab — list every registered limiter, filter by name, expose
reset + delete. List/metrics already render via Wurk::Limiter::Base;
this wrapper adds the name filter documented in §1.2.0+.
Class Method Summary collapse
-
.list(filter: nil) ⇒ Array<String>
Limiter names, optionally filtered to those whose name contains the case-insensitive substring
filter. - .metadata(name) ⇒ Object
-
.rebuild(name) ⇒ Object
Read-only reconstruction (
register: false) from the persisted metadata. -
.reset(name) ⇒ Object
Stats-key reset: drops every
lmtr-stats:/ state key for the named limiter while keeping its metadata + LIST membership so the row remains in the UI. -
.reset_by_prefix(name) ⇒ Object
Metadata-less fallback: wipe every type's un-suffixed state key.
Class Method Details
.list(filter: nil) ⇒ Array<String>
Returns limiter names, optionally filtered to those
whose name contains the case-insensitive substring filter.
27 28 29 30 31 32 33 |
# File 'lib/wurk/web/enterprise.rb', line 27 def list(filter: nil) names = Wurk.redis { |c| c.call('SMEMBERS', Wurk::Limiter::LIST_KEY) }.sort return names if filter.nil? || filter.to_s.empty? needle = filter.to_s.downcase names.select { |n| n.downcase.include?(needle) } end |
.metadata(name) ⇒ Object
35 36 37 38 |
# File 'lib/wurk/web/enterprise.rb', line 35 def (name) raw = Wurk.redis { |c| c.call('HGETALL', "lmtr:#{name}") } raw.is_a?(Array) ? raw.each_slice(2).to_h : raw end |
.rebuild(name) ⇒ Object
Read-only reconstruction (register: false) from the persisted
metadata. Returns nil when the meta HASH is gone or malformed —
LIST membership has no TTL, so a name can outlive its metadata.
56 57 58 59 60 61 62 63 64 |
# File 'lib/wurk/web/enterprise.rb', line 56 def rebuild(name) = (name) return nil if .nil? || .empty? = ['options'] ? ::JSON.parse(['options']) : {} Wurk::Limiter.build(name, ['type'], ) rescue StandardError nil end |
.reset(name) ⇒ Object
Stats-key reset: drops every lmtr-stats: / state key for the
named limiter while keeping its metadata + LIST membership so the
row remains in the UI. Mirrors the §1.5 #reset surface — the
name is wire-compat, so the trailing-? rule doesn't apply here.
44 45 46 47 48 49 50 51 |
# File 'lib/wurk/web/enterprise.rb', line 44 def reset(name) # rubocop:disable Naming/PredicateMethod limiter = rebuild(name) # Reconstruct the limiter and delegate: only the type itself knows # its state keys. A bucket's counter lives at `lmtr-b:<name>:<epoch>`, # so the bare-prefix DEL below never touched it. limiter ? limiter.reset : reset_by_prefix(name) true end |
.reset_by_prefix(name) ⇒ Object
Metadata-less fallback: wipe every type's un-suffixed state key.
67 68 69 70 71 72 |
# File 'lib/wurk/web/enterprise.rb', line 67 def reset_by_prefix(name) Wurk.redis do |c| %W[lmtr-cs:#{name} lmtr-w:#{name} lmtr-l:#{name} lmtr-p:#{name} lmtr-stats:#{name}].each { |k| c.call('DEL', k) } end end |