Class: ProcessLock::WithProcessLock
- Inherits:
-
Object
- Object
- ProcessLock::WithProcessLock
- Defined in:
- lib/process_lock/with_process_lock.rb
Class Method Summary collapse
Class Method Details
.can_execute?(key) ⇒ Boolean
15 16 17 |
# File 'lib/process_lock/with_process_lock.rb', line 15 def self.can_execute?(key) !redis.exists(key) end |
.execute(key, &blk) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 |
# File 'lib/process_lock/with_process_lock.rb', line 3 def self.execute(key, &blk) if can_execute?(key) redis.set(key, true) yield blk redis.del(key) redis.quit else redis.quit raise StandardError, "Can not run process because #{key} taken." end end |
.redis ⇒ Object
19 20 21 |
# File 'lib/process_lock/with_process_lock.rb', line 19 def self.redis @_redis ||= Redis.new end |