eventq_base 1.7.2 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/eventq_base/nonce_error.rb +7 -0
- data/lib/eventq_base/nonce_manager.rb +62 -0
- data/lib/eventq_base/version.rb +1 -1
- data/lib/eventq_base.rb +3 -0
- metadata +46 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4a2ac127f57aef44a90cfea420a1087cd1fcc378
|
4
|
+
data.tar.gz: 990a985365ea09620740ff7a649ee337d66bf308
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e5de8a9e071f90e0fc94bdb092ff6e66940ca6002749697a732c54bd5963d01f5ceb163fe127cf7b0b238006e4f164171803daef72e4a758513330932bc60bec
|
7
|
+
data.tar.gz: 1188228dd7b85272b80e68d80207aa57e93168df7b7b9b796036d9b988e4b7cf2c9d2f3f46ec8be47f204611a583d0e0399470041a2e32ad12e40cfb6005a548
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module EventQ
|
2
|
+
class NonceManager
|
3
|
+
|
4
|
+
def self.configure(server:,timeout:10000,lifespan:3600000)
|
5
|
+
@server_url = server
|
6
|
+
@timeout = timeout
|
7
|
+
@lifespan = lifespan
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.server_url
|
11
|
+
@server_url
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.timeout
|
15
|
+
@timeout
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.lifespan
|
19
|
+
@lifespan
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.process(nonce, &block)
|
23
|
+
|
24
|
+
if @server_url != nil
|
25
|
+
|
26
|
+
process_with_nonce(nonce, block)
|
27
|
+
|
28
|
+
else
|
29
|
+
|
30
|
+
process_without_nonce(block)
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
return true
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.process_with_nonce(nonce, block)
|
39
|
+
@server = Redlock::Client.new([ @server_url ])
|
40
|
+
@redis = Redis.new(url: @server_url)
|
41
|
+
|
42
|
+
lock = @server.lock(nonce, @timeout)
|
43
|
+
if lock == false
|
44
|
+
raise NonceError.new("Message has already been processed: #{nonce}")
|
45
|
+
end
|
46
|
+
|
47
|
+
block.call
|
48
|
+
|
49
|
+
@redis.expire(nonce, @lifespan)
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.process_without_nonce(block)
|
53
|
+
block.call
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.reset
|
57
|
+
@server_url = nil
|
58
|
+
@timeout = nil
|
59
|
+
@lifespan = nil
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/lib/eventq_base/version.rb
CHANGED
data/lib/eventq_base.rb
CHANGED
@@ -2,6 +2,7 @@ require 'class_kit'
|
|
2
2
|
require 'hash_kit'
|
3
3
|
require 'json_kit'
|
4
4
|
require 'oj'
|
5
|
+
require 'redlock'
|
5
6
|
|
6
7
|
require_relative 'eventq_base/version'
|
7
8
|
require_relative 'eventq_base/eventq_logger'
|
@@ -17,4 +18,6 @@ require_relative 'eventq_base/eventq_client_contract'
|
|
17
18
|
require_relative 'eventq_base/configuration'
|
18
19
|
require_relative 'eventq_base/serialization_providers'
|
19
20
|
require_relative 'eventq_base/worker_id'
|
21
|
+
require_relative 'eventq_base/nonce_error'
|
22
|
+
require_relative 'eventq_base/nonce_manager'
|
20
23
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eventq_base
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- vaughanbrittonsage
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-10-
|
11
|
+
date: 2016-10-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,34 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
41
69
|
- !ruby/object:Gem::Dependency
|
42
70
|
name: class_kit
|
43
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,6 +122,20 @@ dependencies:
|
|
94
122
|
- - ">="
|
95
123
|
- !ruby/object:Gem::Version
|
96
124
|
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: redlock
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
97
139
|
description: This gem contains the base classes and contracts required by any eventq
|
98
140
|
implementations.
|
99
141
|
email:
|
@@ -112,6 +154,8 @@ files:
|
|
112
154
|
- lib/eventq_base/eventq_logger.rb
|
113
155
|
- lib/eventq_base/exchange.rb
|
114
156
|
- lib/eventq_base/message_args.rb
|
157
|
+
- lib/eventq_base/nonce_error.rb
|
158
|
+
- lib/eventq_base/nonce_manager.rb
|
115
159
|
- lib/eventq_base/queue.rb
|
116
160
|
- lib/eventq_base/queue_message.rb
|
117
161
|
- lib/eventq_base/queue_worker_contract.rb
|