barrage 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +4 -1
- data/CHANGELOG.md +8 -0
- data/Gemfile +14 -0
- data/README.md +5 -0
- data/barrage.gemspec +2 -2
- data/lib/barrage/generators/redis_worker_id.rb +15 -2
- data/lib/barrage/version.rb +1 -1
- data/spec/barrage/generators/redis_worker_id_spec.rb +35 -1
- metadata +14 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9f4e3f94545667fc55e7efb109d64c1e87f6a382d8ec7ced5f4076c7813f1ea7
|
4
|
+
data.tar.gz: e4e99afca1bf2b0c234349db437dc42fa439199ebce178053e86c9b512dd68bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a538c813035749f2732aa3f445d24636af10980f99ebb6e3072de8a59b2ca194cdd58123e8704e85f78dd62eedefe073717fc324c8e5dbe53352ac536da2cda
|
7
|
+
data.tar.gz: f91dd3eed5970c31b19c42c24739aa396c0766349d25c090a8ee378e7914d2f4cab2ebf20f973376af191212ed250e6c61b772d6731f4b707cc8907d9ed22e87
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
@@ -2,3 +2,17 @@ source 'https://rubygems.org'
|
|
2
2
|
|
3
3
|
# Specify your gem's dependencies in barrage.gemspec
|
4
4
|
gemspec
|
5
|
+
|
6
|
+
if Gem::Version.create(RUBY_VERSION) < Gem::Version.create("2.2.2")
|
7
|
+
gem "activesupport", "< 5.0.0"
|
8
|
+
end
|
9
|
+
|
10
|
+
if Gem::Version.create(RUBY_VERSION) < Gem::Version.create("2.2.3")
|
11
|
+
gem "listen", "< 3.1.0"
|
12
|
+
end
|
13
|
+
|
14
|
+
if Gem::Version.create(RUBY_VERSION) < Gem::Version.create("2.2.5")
|
15
|
+
gem "ruby_dep", "< 1.4.0"
|
16
|
+
end
|
17
|
+
|
18
|
+
gem "redis", ">= 4.0.0"
|
data/README.md
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
# Barrage
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/barrage.svg)](http://badge.fury.io/rb/barrage)
|
4
|
+
[![Dependency Status](https://gemnasium.com/drecom/barrage.svg)](https://gemnasium.com/drecom/barrage)
|
4
5
|
[![Coverage Status](https://img.shields.io/coveralls/drecom/barrage.svg)](https://coveralls.io/r/drecom/barrage)
|
6
|
+
[![Build Status](https://travis-ci.org/drecom/barrage.svg)](https://travis-ci.org/drecom/barrage)
|
7
|
+
[![Code Climate](https://codeclimate.com/github/drecom/barrage.png)](https://codeclimate.com/github/drecom/barrage)
|
5
8
|
|
6
9
|
Distributed ID generator(like twitter/snowflake)
|
7
10
|
|
@@ -44,6 +47,8 @@ barrage.next
|
|
44
47
|
|
45
48
|
#### msec
|
46
49
|
#### redis_worker_id
|
50
|
+
requirement: redis 2.6+
|
51
|
+
|
47
52
|
#### sequence
|
48
53
|
|
49
54
|
### Creating your own generator
|
data/barrage.gemspec
CHANGED
@@ -20,9 +20,9 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_dependency "activesupport"
|
22
22
|
|
23
|
-
spec.add_development_dependency "bundler"
|
23
|
+
spec.add_development_dependency "bundler"
|
24
24
|
spec.add_development_dependency "rake"
|
25
|
-
spec.add_development_dependency "rspec"
|
25
|
+
spec.add_development_dependency "rspec"
|
26
26
|
spec.add_development_dependency "rspec-its"
|
27
27
|
spec.add_development_dependency "pry"
|
28
28
|
spec.add_development_dependency "guard-rspec"
|
@@ -50,7 +50,20 @@ class Barrage
|
|
50
50
|
|
51
51
|
if redis.is_a?(Redis) and redis.connected?
|
52
52
|
redis.del("barrage:worker:#{worker_id}") if real_ttl > Time.now.to_i
|
53
|
-
|
53
|
+
|
54
|
+
close_redis_connection(redis)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def close_redis_connection(redis)
|
61
|
+
redis_version = Gem.loaded_specs["redis"]&.version
|
62
|
+
|
63
|
+
if redis_version && redis_version >= Gem::Version.new("5.0.0")
|
64
|
+
redis._client.close
|
65
|
+
else
|
66
|
+
redis._client.disconnect
|
54
67
|
end
|
55
68
|
end
|
56
69
|
end
|
@@ -63,7 +76,7 @@ class Barrage
|
|
63
76
|
end
|
64
77
|
new_worker_id = redis.evalsha(
|
65
78
|
script_sha,
|
66
|
-
argv: [2 ** length, rand(2 ** length), @worker_id, ttl, RACE_CONDITION_TTL]
|
79
|
+
argv: [2 ** length, rand(2 ** length), (@worker_id || 0), ttl, RACE_CONDITION_TTL]
|
67
80
|
)
|
68
81
|
new_worker_id or raise StandardError, "Renew redis worker id failed"
|
69
82
|
return new_worker_id.to_i
|
data/lib/barrage/version.rb
CHANGED
@@ -30,7 +30,7 @@ describe Barrage::Generators::RedisWorkerId do
|
|
30
30
|
it { is_expected.to be < 2 ** length }
|
31
31
|
|
32
32
|
context "on many instances" do
|
33
|
-
subject {
|
33
|
+
subject { 3.times.map { described_class.new(options) } }
|
34
34
|
let(:length) { 8 }
|
35
35
|
|
36
36
|
it "should generate unique numbers" do
|
@@ -43,4 +43,38 @@ describe Barrage::Generators::RedisWorkerId do
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
46
|
+
|
47
|
+
describe "#Finalizer" do
|
48
|
+
subject { described_class::Finalizer.new(data).call(*args) }
|
49
|
+
|
50
|
+
let(:now) { Time.now.to_i }
|
51
|
+
let(:ttl) { 300 }
|
52
|
+
let(:redis) { Redis.new }
|
53
|
+
let(:worker_ttl) { now + ttl / 2 }
|
54
|
+
let(:real_ttl) { now + ttl }
|
55
|
+
let(:data) { [redis, worker_ttl, real_ttl] }
|
56
|
+
let(:args) { {} }
|
57
|
+
|
58
|
+
if Gem.loaded_specs["redis"]&.version >= Gem::Version.new("5.0.0")
|
59
|
+
before do
|
60
|
+
redis._client.send(:raw_connection)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "redis client disconnect" do
|
64
|
+
subject
|
65
|
+
|
66
|
+
expect(redis.connected?).to be_nil
|
67
|
+
end
|
68
|
+
else
|
69
|
+
before do
|
70
|
+
redis._client.connect
|
71
|
+
end
|
72
|
+
|
73
|
+
it "redis client disconnect" do
|
74
|
+
subject
|
75
|
+
|
76
|
+
expect(redis.connected?).to eq false
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
46
80
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: barrage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- gussan
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-11-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -56,16 +56,16 @@ dependencies:
|
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec-its
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -199,7 +199,7 @@ homepage: http://github.com/drecom/barrage
|
|
199
199
|
licenses:
|
200
200
|
- MIT
|
201
201
|
metadata: {}
|
202
|
-
post_install_message:
|
202
|
+
post_install_message:
|
203
203
|
rdoc_options: []
|
204
204
|
require_paths:
|
205
205
|
- lib
|
@@ -214,9 +214,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
214
214
|
- !ruby/object:Gem::Version
|
215
215
|
version: '0'
|
216
216
|
requirements: []
|
217
|
-
|
218
|
-
|
219
|
-
signing_key:
|
217
|
+
rubygems_version: 3.3.3
|
218
|
+
signing_key:
|
220
219
|
specification_version: 4
|
221
220
|
summary: Distributed id generator
|
222
221
|
test_files:
|