Class: EventQ::NonceManager

Inherits:
Object
  • Object
show all
Defined in:
lib/eventq_base/nonce_manager.rb

Class Method Summary collapse

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

Returns:

  • (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

.lifespanObject



18
19
20
# File 'lib/eventq_base/nonce_manager.rb', line 18

def self.lifespan
  @lifespan
end

.resetObject



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_urlObject



10
11
12
# File 'lib/eventq_base/nonce_manager.rb', line 10

def self.server_url
  @server_url
end

.timeoutObject



14
15
16
# File 'lib/eventq_base/nonce_manager.rb', line 14

def self.timeout
  @timeout
end