global_uid 2.0.2 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/global_uid/base.rb +14 -8
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2f325cebc1181d89219847ff9f174cbeb40de406
4
- data.tar.gz: c8d665219da03e0617511e3f80f8a7827868d495
3
+ metadata.gz: f17fa1ca013a3522b17564a1a5221f6808fe5a13
4
+ data.tar.gz: 2768edccf2ce2c846149b346533ef1723e0f4cea
5
5
  SHA512:
6
- metadata.gz: eb69c8c2235fa511d941437efbd9d22a5cae2019ba786168f6bea886da7a7f9f1a16291d84dc1d270ea4039b90507ec04eeb303efa768e0186e4431fd4c6e50f
7
- data.tar.gz: 409cf53d8f1ed676d72fb57cfd4c167ccb3ff38688663e8699f4219574ed2819175837b20b82816a2411057705f727b34741229d6962364fd2e899cae2a26931
6
+ metadata.gz: 2ad21dd9b622a6c67314474d14b8150293a9b8c54350090e91ed58abd17cbe847280c0b6992b28db3c496ba9373e2dcd90ac791e2eca69cc4672d42d986f93fa
7
+ data.tar.gz: 9b5e0e4f6a14f99c120cf5d1cd8cdab218bb886e260123fb3537c1dd8c47987a1287e1319c840f990d271e719fc302fa5a7b2c6ad83b683a6ef03d16d55bda8b
@@ -11,8 +11,6 @@ end
11
11
 
12
12
  module GlobalUid
13
13
  class Base
14
- @@servers = nil
15
-
16
14
  GLOBAL_UID_DEFAULTS = {
17
15
  :connection_timeout => 3,
18
16
  :connection_retry => 10.minutes,
@@ -24,6 +22,14 @@ module GlobalUid
24
22
  :dry_run => false
25
23
  }
26
24
 
25
+ def self.servers
26
+ Thread.current[:servers]
27
+ end
28
+
29
+ def self.servers=(s)
30
+ Thread.current[:servers] = s
31
+ end
32
+
27
33
  def self.create_uid_tables(id_table_name, options={})
28
34
  type = options[:uid_type] || "bigint(21) UNSIGNED"
29
35
  start_id = options[:start_id] || 1
@@ -106,20 +112,20 @@ module GlobalUid
106
112
  end
107
113
 
108
114
  def self.disconnect!
109
- @@servers = nil
115
+ self.servers = nil
110
116
  end
111
117
 
112
118
  def self.setup_connections!(options)
113
119
  connection_timeout = options[:connection_timeout]
114
120
  increment_by = options[:increment_by]
115
121
 
116
- if @@servers.nil?
117
- @@servers = init_server_info(options)
122
+ if self.servers.nil?
123
+ self.servers = init_server_info(options)
118
124
  # sorting here sets up each process to have affinity to a particular server.
119
- @@servers = @@servers.sort_by { |s| s[:rand] }
125
+ self.servers = self.servers.sort_by { |s| s[:rand] }
120
126
  end
121
127
 
122
- @@servers.each do |info|
128
+ self.servers.each do |info|
123
129
  next if info[:cx]
124
130
 
125
131
  if info[:new?] || ( info[:retry_at] && Time.now > info[:retry_at] )
@@ -131,7 +137,7 @@ module GlobalUid
131
137
  end
132
138
  end
133
139
 
134
- @@servers
140
+ self.servers
135
141
  end
136
142
 
137
143
  def self.with_connections(options = {})
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: global_uid
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Osheroff
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-10 00:00:00.000000000 Z
11
+ date: 2014-10-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord