bellbro 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bellbro.rb +1 -1
- data/lib/bellbro/initialize.rb +11 -17
- data/lib/bellbro/redis_pool.rb +38 -0
- data/lib/bellbro/service.rb +4 -4
- data/lib/bellbro/settings.rb +10 -5
- data/lib/bellbro/version.rb +1 -1
- metadata +2 -2
- data/lib/bellbro/pool.rb +0 -37
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7972910ac6f1f1bb5d63498b04dce2c62e0a40f7
|
4
|
+
data.tar.gz: eb62c1ae4184d2484c814542819934dd55c2e4af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99e337067fe1357a3fba9d8776e9c65d6133f726dec8517c62d8e571fbd589c1b14fa66d989c5143d110f747e6f339ca2b6d0ceb2c0225f0b5efa659a9d6febc
|
7
|
+
data.tar.gz: d4c61918923e5b993ac00a008deffee47b086ded6b0ca79e8624852e5ccd60dd98a706034f64b88bad9a512cee1592e1fa717a203fd2588695229787674c9e81
|
data/lib/bellbro.rb
CHANGED
data/lib/bellbro/initialize.rb
CHANGED
@@ -1,30 +1,24 @@
|
|
1
1
|
module Bellbro
|
2
|
-
def self.
|
2
|
+
def self.initialize_redis!
|
3
3
|
return unless defined?(Rails)
|
4
4
|
filename = "#{Rails.root}/config/redis.yml"
|
5
5
|
return unless File.exists?(filename)
|
6
|
-
|
7
6
|
config = YAML.load_file(filename)[Rails.env]
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
puts "## Initializing redis pool with size #{size} and url #{url}"
|
12
|
-
pool = ConnectionPool.new(size: size) do
|
13
|
-
Redis.new(url: url)
|
14
|
-
end
|
7
|
+
configure_bellbro(config)
|
8
|
+
end
|
15
9
|
|
16
|
-
|
10
|
+
def self.configure_bellbro(config)
|
11
|
+
redis_url = Figaro.env.redis_url
|
12
|
+
databases = ThreadSafe::Cache.new
|
17
13
|
config['databases'].each do |name, db|
|
18
14
|
puts "## Db name #{name} mapped to #{db}"
|
19
|
-
|
15
|
+
databases[name.to_sym] = db
|
20
16
|
end
|
21
17
|
|
22
|
-
Bellbro::Settings.configure do |
|
23
|
-
|
24
|
-
|
18
|
+
Bellbro::Settings.configure do |con|
|
19
|
+
con.redis_databases = databases
|
20
|
+
con.redis_url = redis_url
|
21
|
+
con.redis_pool_size = config['pool']
|
25
22
|
end
|
26
23
|
end
|
27
24
|
end
|
28
|
-
|
29
|
-
Bellbro.initialize!
|
30
|
-
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Bellbro
|
2
|
+
module RedisPool
|
3
|
+
def with_connection
|
4
|
+
self.class.with_connection do |c|
|
5
|
+
yield c
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.included(klass)
|
10
|
+
class << klass
|
11
|
+
|
12
|
+
def set_db(default)
|
13
|
+
@default_db_name = default.to_sym
|
14
|
+
end
|
15
|
+
|
16
|
+
def with_connection
|
17
|
+
retryable(sleep: 0.5) do
|
18
|
+
Sidekiq.redis do |c|
|
19
|
+
c.select(model_db)
|
20
|
+
val = yield c
|
21
|
+
c.select(sidekiq_db)
|
22
|
+
val
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def model_db
|
28
|
+
@model_db ||= Bellbro::Settings.redis_databases[@default_db_name]
|
29
|
+
end
|
30
|
+
|
31
|
+
def sidekiq_db
|
32
|
+
@sidekiq_db ||= Bellbro::Settings.redis_databases[:sidekiq]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/bellbro/service.rb
CHANGED
@@ -52,13 +52,13 @@ module Bellbro
|
|
52
52
|
|
53
53
|
def run
|
54
54
|
ring "Starting #{self.class} service."
|
55
|
-
|
55
|
+
self.class.mutex.synchronize { track }
|
56
56
|
begin
|
57
|
-
|
58
|
-
|
57
|
+
self.class.mutex.synchronize { start_jobs }
|
58
|
+
self.class.mutex.synchronize { status_update }
|
59
59
|
sleep
|
60
60
|
end until @done
|
61
|
-
|
61
|
+
self.class.mutex.synchronize { stop_tracking }
|
62
62
|
end
|
63
63
|
|
64
64
|
def start_jobs
|
data/lib/bellbro/settings.rb
CHANGED
@@ -2,7 +2,7 @@ module Bellbro
|
|
2
2
|
module Settings
|
3
3
|
|
4
4
|
class SettingsData < Struct.new(
|
5
|
-
:logger, :env, :
|
5
|
+
:logger, :env, :redis_databases, :redis_pool_size, :redis_url
|
6
6
|
)
|
7
7
|
end
|
8
8
|
|
@@ -24,14 +24,19 @@ module Bellbro
|
|
24
24
|
configuration.env == 'test'
|
25
25
|
end
|
26
26
|
|
27
|
-
def self.
|
27
|
+
def self.redis_databases
|
28
28
|
return unless configured?
|
29
|
-
configuration.
|
29
|
+
configuration.redis_databases
|
30
30
|
end
|
31
31
|
|
32
|
-
def self.
|
32
|
+
def self.redis_pool_size
|
33
33
|
return unless configured?
|
34
|
-
configuration.
|
34
|
+
configuration.redis_pool_size
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.redis_url
|
38
|
+
return unless configured?
|
39
|
+
configuration.redis_url
|
35
40
|
end
|
36
41
|
|
37
42
|
def self.logger
|
data/lib/bellbro/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bellbro
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jon Stokes
|
@@ -140,7 +140,7 @@ files:
|
|
140
140
|
- lib/bellbro/hooks.rb
|
141
141
|
- lib/bellbro/initialize.rb
|
142
142
|
- lib/bellbro/keyable.rb
|
143
|
-
- lib/bellbro/
|
143
|
+
- lib/bellbro/redis_pool.rb
|
144
144
|
- lib/bellbro/retryable.rb
|
145
145
|
- lib/bellbro/ringable.rb
|
146
146
|
- lib/bellbro/service.rb
|
data/lib/bellbro/pool.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
module Bellbro
|
2
|
-
module Pool
|
3
|
-
|
4
|
-
def with_connection(key: nil)
|
5
|
-
key ||= db_name
|
6
|
-
db = directory(key)
|
7
|
-
retryable(sleep: 0.5) do
|
8
|
-
Bellbro::Settings.connection_pool.with do |c|
|
9
|
-
c.select(db)
|
10
|
-
yield c
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def db_name
|
16
|
-
self.class.db_name
|
17
|
-
end
|
18
|
-
|
19
|
-
def directory(name)
|
20
|
-
Bellbro::Settings.db_directory[name]
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.included(klass)
|
24
|
-
klass.extend(self)
|
25
|
-
|
26
|
-
class << klass
|
27
|
-
def set_db(db_name)
|
28
|
-
@db_name = db_name
|
29
|
-
end
|
30
|
-
|
31
|
-
def db_name
|
32
|
-
@db_name
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|