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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9f80161fa7b7eff787e56b318ffd60b31db7ac06
4
- data.tar.gz: d8d60490af0e0b9e69ffc64925f1a9c14635afcd
3
+ metadata.gz: 7972910ac6f1f1bb5d63498b04dce2c62e0a40f7
4
+ data.tar.gz: eb62c1ae4184d2484c814542819934dd55c2e4af
5
5
  SHA512:
6
- metadata.gz: 345da04d9bbd62965fef9621577b0732520b9dede48c04b9de5263ff5bbecfa1dd42e18f828479e359a4cae7c37a09664b7dbeb72463405800b2fe2daeedf069
7
- data.tar.gz: 91fd5fdf99169e189f42a62f8ceff82585366b7b769cc06cfb8998826bc2e2724973b9a47bb84255b448073af35d205e8e445410da68834e59ff5d4377801ab0
6
+ metadata.gz: 99e337067fe1357a3fba9d8776e9c65d6133f726dec8517c62d8e571fbd589c1b14fa66d989c5143d110f747e6f339ca2b6d0ceb2c0225f0b5efa659a9d6febc
7
+ data.tar.gz: d4c61918923e5b993ac00a008deffee47b086ded6b0ca79e8624852e5ccd60dd98a706034f64b88bad9a512cee1592e1fa717a203fd2588695229787674c9e81
data/lib/bellbro.rb CHANGED
@@ -14,7 +14,7 @@ require 'airbrake'
14
14
  bellbro/retryable.rb
15
15
  bellbro/ringable.rb
16
16
  bellbro/trackable.rb
17
- bellbro/pool.rb
17
+ bellbro/redis_pool.rb
18
18
  bellbro/sidekiq_utils.rb
19
19
  bellbro/bell.rb
20
20
  bellbro/service.rb
@@ -1,30 +1,24 @@
1
1
  module Bellbro
2
- def self.initialize!
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
- url = Figaro.env.send(config['url'].downcase)
9
- size = config['pool']
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
- directory = ThreadSafe::Cache.new
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
- directory[name.to_sym] = db
15
+ databases[name.to_sym] = db
20
16
  end
21
17
 
22
- Bellbro::Settings.configure do |config|
23
- config.connection_pool = pool
24
- config.db_directory = directory
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
@@ -52,13 +52,13 @@ module Bellbro
52
52
 
53
53
  def run
54
54
  ring "Starting #{self.class} service."
55
- Service.mutex.synchronize { track }
55
+ self.class.mutex.synchronize { track }
56
56
  begin
57
- Service.mutex.synchronize { start_jobs }
58
- Service.mutex.synchronize { status_update }
57
+ self.class.mutex.synchronize { start_jobs }
58
+ self.class.mutex.synchronize { status_update }
59
59
  sleep
60
60
  end until @done
61
- Service.mutex.synchronize { stop_tracking }
61
+ self.class.mutex.synchronize { stop_tracking }
62
62
  end
63
63
 
64
64
  def start_jobs
@@ -2,7 +2,7 @@ module Bellbro
2
2
  module Settings
3
3
 
4
4
  class SettingsData < Struct.new(
5
- :logger, :env, :connection_pool, :db_directory
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.connection_pool
27
+ def self.redis_databases
28
28
  return unless configured?
29
- configuration.connection_pool
29
+ configuration.redis_databases
30
30
  end
31
31
 
32
- def self.db_directory
32
+ def self.redis_pool_size
33
33
  return unless configured?
34
- configuration.db_directory
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
@@ -1,3 +1,3 @@
1
1
  module Bellbro
2
- VERSION = '0.1.4'
2
+ VERSION = '0.2.0'
3
3
  end
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.1.4
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/pool.rb
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