Module: RubyReactor::Dsl::Lockable::ClassMethods
- Defined in:
- lib/ruby_reactor/dsl/lockable.rb
Instance Attribute Summary collapse
-
#lock_config ⇒ Object
readonly
Returns the value of attribute lock_config.
-
#ordered_lock_config ⇒ Object
readonly
Returns the value of attribute ordered_lock_config.
-
#period_config ⇒ Object
readonly
Returns the value of attribute period_config.
-
#rate_limit_config ⇒ Object
readonly
Returns the value of attribute rate_limit_config.
-
#semaphore_config ⇒ Object
readonly
Returns the value of attribute semaphore_config.
Instance Method Summary collapse
-
#inherited(subclass) ⇒ Object
Propagate lock/semaphore/period/rate-limit config to subclasses; without this a subclass of a configured reactor would silently lose those settings.
-
#with_lock(ttl: 60, wait: 0, auto_extend: true) {|inputs| ... } ⇒ Object
Configure locking for this reactor.
-
#with_ordered_lock(poison_pill_timeout: OrderedLock::DEFAULT_POISON_PILL_TIMEOUT, ttl: OrderedLock::DEFAULT_TTL, strict: true) {|inputs| ... } ⇒ Object
Configure strict-ordering nonce gating for this reactor.
-
#with_period(every:) {|inputs| ... } ⇒ Object
Configure a calendar-aligned dedup window for this reactor.
-
#with_rate_limit(name = nil, limit: nil, period: nil, limits: nil) {|inputs| ... } ⇒ Object
Configure rate limiting for this reactor (fixed-window counter).
-
#with_semaphore(limit:, wait: 0) {|inputs| ... } ⇒ Object
Configure semaphore for this reactor.
Instance Attribute Details
#lock_config ⇒ Object (readonly)
Returns the value of attribute lock_config.
11 12 13 |
# File 'lib/ruby_reactor/dsl/lockable.rb', line 11 def lock_config @lock_config end |
#ordered_lock_config ⇒ Object (readonly)
Returns the value of attribute ordered_lock_config.
11 12 13 |
# File 'lib/ruby_reactor/dsl/lockable.rb', line 11 def ordered_lock_config @ordered_lock_config end |
#period_config ⇒ Object (readonly)
Returns the value of attribute period_config.
11 12 13 |
# File 'lib/ruby_reactor/dsl/lockable.rb', line 11 def period_config @period_config end |
#rate_limit_config ⇒ Object (readonly)
Returns the value of attribute rate_limit_config.
11 12 13 |
# File 'lib/ruby_reactor/dsl/lockable.rb', line 11 def rate_limit_config @rate_limit_config end |
#semaphore_config ⇒ Object (readonly)
Returns the value of attribute semaphore_config.
11 12 13 |
# File 'lib/ruby_reactor/dsl/lockable.rb', line 11 def semaphore_config @semaphore_config end |
Instance Method Details
#inherited(subclass) ⇒ Object
Propagate lock/semaphore/period/rate-limit config to subclasses; without this a subclass of a configured reactor would silently lose those settings.
16 17 18 19 20 21 22 23 |
# File 'lib/ruby_reactor/dsl/lockable.rb', line 16 def inherited(subclass) super subclass.instance_variable_set(:@lock_config, @lock_config) if @lock_config subclass.instance_variable_set(:@semaphore_config, @semaphore_config) if @semaphore_config subclass.instance_variable_set(:@period_config, @period_config) if @period_config subclass.instance_variable_set(:@rate_limit_config, @rate_limit_config) if @rate_limit_config subclass.instance_variable_set(:@ordered_lock_config, @ordered_lock_config) if @ordered_lock_config end |
#with_lock(ttl: 60, wait: 0, auto_extend: true) {|inputs| ... } ⇒ Object
Configure locking for this reactor
33 34 35 36 37 38 39 40 |
# File 'lib/ruby_reactor/dsl/lockable.rb', line 33 def with_lock(ttl: 60, wait: 0, auto_extend: true, &block) @lock_config = { ttl: ttl, wait: wait, auto_extend: auto_extend, key_proc: block } end |
#with_ordered_lock(poison_pill_timeout: OrderedLock::DEFAULT_POISON_PILL_TIMEOUT, ttl: OrderedLock::DEFAULT_TTL, strict: true) {|inputs| ... } ⇒ Object
Configure strict-ordering nonce gating for this reactor. A monotonically increasing nonce is assigned at enqueue time; the worker can only proceed when its nonce equals ‘last_completed + 1`. Otherwise the worker raises OrderedLock::WaitError and the Sidekiq worker snoozes via `perform_in`.
Counters reset to 0 once the sequence fully drains (last_completed catches up to next). Re-entrancy is NOT supported — a nested reactor with its own ‘with_ordered_lock` is an independent sequence.
105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/ruby_reactor/dsl/lockable.rb', line 105 def with_ordered_lock(poison_pill_timeout: OrderedLock::DEFAULT_POISON_PILL_TIMEOUT, ttl: OrderedLock::DEFAULT_TTL, strict: true, &block) @ordered_lock_config = { poison_pill_timeout: poison_pill_timeout, ttl: ttl, strict: strict, key_proc: block } end |
#with_period(every:) {|inputs| ... } ⇒ Object
Configure a calendar-aligned dedup window for this reactor. The reactor will run at most once per bucket per key; subsequent calls in the same bucket return ‘RubyReactor::Skipped` without executing any steps.
Note: ‘with_period` is dedup, not concurrency. Two concurrent racers can both see no marker and both run. Pair with `with_lock` for true at-most-one semantics within the bucket.
68 69 70 71 72 73 74 75 76 |
# File 'lib/ruby_reactor/dsl/lockable.rb', line 68 def with_period(every:, &block) # Validate eagerly so misconfiguration surfaces at class load time. RubyReactor::Period.period_seconds(every) @period_config = { every: every, key_proc: block } end |
#with_rate_limit(name = nil, limit: nil, period: nil, limits: nil) {|inputs| ... } ⇒ Object
Configure rate limiting for this reactor (fixed-window counter). Pass either a single window via ‘limit:` + `period:`, or a hash of windows via `limits:` for layered API quotas.
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/ruby_reactor/dsl/lockable.rb', line 142 def with_rate_limit(name = nil, limit: nil, period: nil, limits: nil, &block) if name if limit || period || limits || block raise ArgumentError, "with_rate_limit(:#{name}) references a registered limit; " \ "do not also pass :limit/:period/:limits or a block" end @rate_limit_config = { name: name.to_sym } return end @rate_limit_config = { limits: RubyReactor::RateLimit.normalize_specs(limit: limit, period: period, limits: limits), key_proc: block } end |
#with_semaphore(limit:, wait: 0) {|inputs| ... } ⇒ Object
Configure semaphore for this reactor
46 47 48 49 50 51 52 |
# File 'lib/ruby_reactor/dsl/lockable.rb', line 46 def with_semaphore(limit:, wait: 0, &block) @semaphore_config = { limit: limit, wait: wait, key_proc: block } end |