Class: Pgbus::Configuration::CapsuleDSL
- Inherits:
-
Object
- Object
- Pgbus::Configuration::CapsuleDSL
- Defined in:
- lib/pgbus/configuration/capsule_dsl.rb
Overview
Parses the capsule string DSL into the internal worker config array.
The DSL lets users describe worker thread pools (capsules) compactly:
"*: 5" # one capsule, all queues, 5 threads
"critical: 5; default: 10" # two capsules
"critical, default: 5" # one capsule, list = strict priority
"default, mailers: 10; *: 2" # specialized + fallback wildcard
"staging_*: 3" # prefix wildcard
Operators:
, queue separator within a capsule (list order = strict priority)
; capsule separator (each becomes its own thread pool)
:N thread count for the capsule (default 5)
* wildcard, matches all queues
*_ trailing wildcard, prefix match (e.g. "staging_*")
Returns Array<Hash> in the same shape as the legacy workers: array, so the rest of the codebase can consume it without changes:
[{ queues: ["critical"], threads: 5 },
{ queues: ["default", "mailers"], threads: 10 }]
Validation runs at parse time. Errors include the offending input and a clear message naming the rule that was violated.
Defined Under Namespace
Classes: ParseError
Constant Summary collapse
- DEFAULT_THREADS =
5- WILDCARD =
"*"- QUEUE_NAME_PATTERN =
Valid queue tokens accepted by the DSL:
"*" bare wildcard (matches all queues at runtime) "default" bare queue name "staging_*" prefix wildcard (matches queues by prefix at runtime)The character class for queue names — alphanumerics and underscores only — intentionally matches Pgbus::QueueNameValidator::VALID_QUEUE_NAME_PATTERN. Hyphens, dots, and other punctuation are NOT permitted because PGMQ interpolates queue names directly into SQL identifiers (q_<name>, a_<name>) and only those characters are safe there. If you change this pattern, also update QueueNameValidator to keep them in sync.
The “*” tokens (bare and trailing) are DSL-only — they get expanded to concrete queue names at runtime before reaching QueueNameValidator.
/\A(?:\*|[a-zA-Z0-9_]+\*?)\z/- THREAD_COUNT_PATTERN =
/\A\d+\z/
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(input) ⇒ CapsuleDSL
constructor
A new instance of CapsuleDSL.
- #parse ⇒ Object
Constructor Details
#initialize(input) ⇒ CapsuleDSL
Returns a new instance of CapsuleDSL.
57 58 59 |
# File 'lib/pgbus/configuration/capsule_dsl.rb', line 57 def initialize(input) @input = input end |
Class Method Details
.parse(input) ⇒ Object
53 54 55 |
# File 'lib/pgbus/configuration/capsule_dsl.rb', line 53 def self.parse(input) new(input).parse end |
Instance Method Details
#parse ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/pgbus/configuration/capsule_dsl.rb', line 61 def parse validate_input_type! validate_input_not_empty! # Pure tokenization: split, parse each capsule, return them in order. # Cross-capsule overlap rules live in Pgbus::Configuration#workers= # because they depend on whether the resulting capsules are named or # anonymous, and naming is a Configuration concern (not a parser one). # Within-capsule duplicate-queue checks still happen in parse_capsule. split_capsules(@input).map { |segment| parse_capsule(segment) } end |