diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e8c96b..cc9029b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ ## [Unreleased] -### [1.11.0] - 2024-08-11 +## [1.12.0] - 2024-08-11 +### Changed +- Timed blocks of code and their timeout errors: reduced error message object allocations; + +## [1.11.0] - 2024-08-11 ### Changed - Lock Acquierment Timeout (`acq_timeout`/`queue_ttl`): more correct timeout error interception inside the `RedisQueuedLocks::Acquier::AcquireLock::WithAcqTimeout` logic that now raises and diff --git a/Gemfile.lock b/Gemfile.lock index 9d51dac..2e3ba89 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - redis_queued_locks (1.11.0) + redis_queued_locks (1.12.0) qonfig (~> 0.28) redis-client (~> 0.20) diff --git a/lib/redis_queued_locks/acquier/acquire_lock/with_acq_timeout.rb b/lib/redis_queued_locks/acquier/acquire_lock/with_acq_timeout.rb index 436a174..ad4a5f9 100644 --- a/lib/redis_queued_locks/acquier/acquire_lock/with_acq_timeout.rb +++ b/lib/redis_queued_locks/acquier/acquire_lock/with_acq_timeout.rb @@ -19,6 +19,8 @@ module RedisQueuedLocks::Acquier::AcquireLock::WithAcqTimeout # Callback invoked on Timeout::Error. # @return [Any] # + # @raise [RedisQueuedLocks::LockAcquiermentIntermediateTimeoutError] + # # @api private # @since 1.0.0 # @version 1.11.0 diff --git a/lib/redis_queued_locks/acquier/acquire_lock/yield_expire.rb b/lib/redis_queued_locks/acquier/acquire_lock/yield_expire.rb index 21941ca..79dd425 100644 --- a/lib/redis_queued_locks/acquier/acquire_lock/yield_expire.rb +++ b/lib/redis_queued_locks/acquier/acquire_lock/yield_expire.rb @@ -107,28 +107,22 @@ def yield_expire( # @param block [Blcok] # @return [Any] # + # @raise [RedisQueuedLocks::TimedLockTimeoutError] + # # @api private # @since 1.3.0 - # @version 1.10.0 + # @version 1.12.0 def yield_with_timeout(timeout, lock_key, lock_ttl, acquier_id, host_id, meta, &block) - ::Timeout.timeout( - timeout, + ::Timeout.timeout(timeout, RedisQueuedLocks::TimedLockIntermediateTimeoutError, &block) + rescue RedisQueuedLocks::TimedLockIntermediateTimeoutError + raise( RedisQueuedLocks::TimedLockTimeoutError, - # NOTE: - # - this string is generated on each invocation cuz we need to raise custom exception - # from the Timeout API in order to prevent incorred Timeout::Error interception when - # the intercepted error is caused from the block not from the RQL; - # - we can't omit this string object creation at the moment via original Ruby's Timeout API; - # TODO: - # - refine Timeout#timeout (via Ruby's Refinement API) in order to provide lazy exception - # message initialization; "Passed block of code exceeded the lock TTL " \ "(lock: \"#{lock_key}\", " \ "ttl: #{lock_ttl}, " \ "meta: #{meta ? meta.inspect : ''}, " \ "acq_id: \"#{acquier_id}\", " \ "hst_id: \"#{host_id}\")", - &block ) end end diff --git a/lib/redis_queued_locks/errors.rb b/lib/redis_queued_locks/errors.rb index ed75064..6881c45 100644 --- a/lib/redis_queued_locks/errors.rb +++ b/lib/redis_queued_locks/errors.rb @@ -25,6 +25,10 @@ module RedisQueuedLocks # @since 1.0.0 LockAcquiermentRetryLimitError = Class.new(Error) + # @api private + # @since 1.12.0 + TimedLockIntermediateTimeoutError = Class.new(::Timeout::Error) + # @api pulic # @since 1.0.0 TimedLockTimeoutError = Class.new(Error) diff --git a/lib/redis_queued_locks/version.rb b/lib/redis_queued_locks/version.rb index 64c228e..5328810 100644 --- a/lib/redis_queued_locks/version.rb +++ b/lib/redis_queued_locks/version.rb @@ -5,6 +5,6 @@ module RedisQueuedLocks # # @api public # @since 0.0.1 - # @version 1.11.0 - VERSION = '1.11.0' + # @version 1.12.0 + VERSION = '1.12.0' end