Class: EventQ::NonceManager
- Inherits:
-
Object
- Object
- EventQ::NonceManager
- Defined in:
- lib/eventq_base/nonce_manager.rb
Class Method Summary collapse
- .complete(nonce) ⇒ Object
- .configure(server:, timeout: 10000, lifespan: 3600000) ⇒ Object
- .failed(nonce) ⇒ Object
- .is_allowed?(nonce) ⇒ Boolean
- .lifespan ⇒ Object
- .reset ⇒ Object
- .server_url ⇒ Object
- .timeout ⇒ Object
Class Method Details
.complete(nonce) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/eventq_base/nonce_manager.rb', line 37 def self.complete(nonce) if @server_url != nil Redis.new(url: @server_url).expire(nonce, @lifespan) end return true end |
.configure(server:, timeout: 10000, lifespan: 3600000) ⇒ Object
4 5 6 7 8 |
# File 'lib/eventq_base/nonce_manager.rb', line 4 def self.configure(server:,timeout:10000,lifespan:3600000) @server_url = server @timeout = timeout @lifespan = lifespan end |
.failed(nonce) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/eventq_base/nonce_manager.rb', line 44 def self.failed(nonce) if @server_url != nil Redis.new(url: @server_url).del(nonce) end return true end |
.is_allowed?(nonce) ⇒ Boolean
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/eventq_base/nonce_manager.rb', line 22 def self.is_allowed?(nonce) if @server_url == nil return true end require 'redlock' lock = Redlock::Client.new([ @server_url ]).lock(nonce, @timeout) if lock == false EventQ.log(:info, "[#{self.class}] - Message has already been processed: #{nonce}") return false end return true end |
.lifespan ⇒ Object
18 19 20 |
# File 'lib/eventq_base/nonce_manager.rb', line 18 def self.lifespan @lifespan end |
.reset ⇒ Object
51 52 53 54 55 |
# File 'lib/eventq_base/nonce_manager.rb', line 51 def self.reset @server_url = nil @timeout = nil @lifespan = nil end |
.server_url ⇒ Object
10 11 12 |
# File 'lib/eventq_base/nonce_manager.rb', line 10 def self.server_url @server_url end |
.timeout ⇒ Object
14 15 16 |
# File 'lib/eventq_base/nonce_manager.rb', line 14 def self.timeout @timeout end |