Skip to content

Commit

Permalink
[timed:true/timed invocations] reduced error message object allocations
Browse files Browse the repository at this point in the history
  • Loading branch information
0exp committed Aug 11, 2024
1 parent 4316c7b commit eb11106
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 16 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 6 additions & 12 deletions lib/redis_queued_locks/acquier/acquire_lock/yield_expire.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 <timed> block of code exceeded the lock TTL " \
"(lock: \"#{lock_key}\", " \
"ttl: #{lock_ttl}, " \
"meta: #{meta ? meta.inspect : '<no-meta>'}, " \
"acq_id: \"#{acquier_id}\", " \
"hst_id: \"#{host_id}\")",
&block
)
end
end
4 changes: 4 additions & 0 deletions lib/redis_queued_locks/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions lib/redis_queued_locks/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit eb11106

Please sign in to comment.