Class: Daemon::Utils::AutoDeletedHash
- Inherits:
-
Redis::HashKey
- Object
- Redis::HashKey
- Daemon::Utils::AutoDeletedHash
- Includes:
- Loggable
- Defined in:
- lib/onapp/engine/utils/auto_deleted_hash.rb
Overview
-
AutoDeletedHash is hash-like object
-
Information is stored directly in redis
-
When process dies, this hash will be automatically expired and deleted by redis
Direct Known Subclasses
Constant Summary
- REFRESH_TIME =
5- EXPIRATION_TIME =
10
Class Attribute Summary (collapse)
Instance Method Summary (collapse)
-
- (AutoDeletedHash) initialize(key, auto_delete: true, redis: nil)
constructor
A new instance of AutoDeletedHash.
- - (Object) logger
- - (Object) refresh
-
- (Object) size
Don't count key which is set in #initialize.
Methods included from Loggable
#debug, #error, #fatal, #info, #lwarn
Constructor Details
- (AutoDeletedHash) initialize(key, auto_delete: true, redis: nil)
Returns a new instance of AutoDeletedHash
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/onapp/engine/utils/auto_deleted_hash.rb', line 42 def initialize(key, auto_delete: true, redis: nil) super(key) @facility = 'autodeleted hash' @myredis = redis if auto_delete refresh Daemon::Utils::EM.run self.class.timers.set_timer(key, REFRESH_TIME) { refresh } end end |
Class Attribute Details
+ (Object) logger
33 34 35 |
# File 'lib/onapp/engine/utils/auto_deleted_hash.rb', line 33 def logger @logger ||= Daemon.logger end |
+ (Object) timers
37 38 39 |
# File 'lib/onapp/engine/utils/auto_deleted_hash.rb', line 37 def timers @timers ||= Daemon::Supervision::Timers.new end |
Instance Method Details
- (Object) logger
54 55 56 |
# File 'lib/onapp/engine/utils/auto_deleted_hash.rb', line 54 def logger self.class.logger end |
- (Object) refresh
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/onapp/engine/utils/auto_deleted_hash.rb', line 58 def refresh debug { "refresh" } Daemon::Utils::Retry.retry( Redis::BaseError, on_error: proc{ |ex| error { "Can't refresh autodeleted hash with key #{key.inspect}. #{ex.class}: #{ex.}\n#{ex.backtrace.join("\n")}\nRetrying..." } }, sleep: 1 ) do store(key, Time.now.utc.to_s) expire(EXPIRATION_TIME) end end |
- (Object) size
Don't count key which is set in #initialize
73 74 75 |
# File 'lib/onapp/engine/utils/auto_deleted_hash.rb', line 73 def size super - 1 end |