Class: UniqueThread::Locksmith
- Inherits:
-
Object
- Object
- UniqueThread::Locksmith
- Defined in:
- lib/unique_thread/locksmith.rb
Defined Under Namespace
Classes: RedisResult
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#redis ⇒ Object
readonly
Returns the value of attribute redis.
-
#stopwatch ⇒ Object
readonly
Returns the value of attribute stopwatch.
Instance Method Summary collapse
-
#initialize(name:, stopwatch:, redis:, logger:) ⇒ Locksmith
constructor
A new instance of Locksmith.
- #new_lock ⇒ Object
- #renew_lock(lock) ⇒ Object
Constructor Details
#initialize(name:, stopwatch:, redis:, logger:) ⇒ Locksmith
Returns a new instance of Locksmith.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/unique_thread/locksmith.rb', line 7 def initialize(name:, stopwatch:, redis:, logger:) @name = name @stopwatch = stopwatch @redis = redis @logger = logger @lua_scripts = Hash[Dir[File.join(__dir__, 'redis_lua', '*.lua')].map do |lua_file| [File.basename(lua_file, '.lua').to_sym, redis.script(:load, File.read(lua_file))] end] end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
5 6 7 |
# File 'lib/unique_thread/locksmith.rb', line 5 def logger @logger end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/unique_thread/locksmith.rb', line 5 def name @name end |
#redis ⇒ Object (readonly)
Returns the value of attribute redis.
5 6 7 |
# File 'lib/unique_thread/locksmith.rb', line 5 def redis @redis end |
#stopwatch ⇒ Object (readonly)
Returns the value of attribute stopwatch.
5 6 7 |
# File 'lib/unique_thread/locksmith.rb', line 5 def stopwatch @stopwatch end |
Instance Method Details
#new_lock ⇒ Object
18 19 20 |
# File 'lib/unique_thread/locksmith.rb', line 18 def new_lock lock_from_redis_command(:get_lock, name, stopwatch.now, stopwatch.next_renewal) end |
#renew_lock(lock) ⇒ Object
22 23 24 |
# File 'lib/unique_thread/locksmith.rb', line 22 def renew_lock(lock) lock_from_redis_command(:extend_lock, name, lock.locked_until, stopwatch.next_renewal) end |