phobos_db_checkpoint 3.1.0 → 3.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: c361b6d8f5d6d96d2d1e4f4e71727c6fa292d6c5
4
- data.tar.gz: 347523a5073e6c63dd04204f6f68d3dba692d94f
3
+ metadata.gz: fb0abf033362b2d16951eea469a851873acbc863
4
+ data.tar.gz: 6f92192149a9ee9cbf82895c6f13329b4a87b032
5
5
  SHA512:
6
- metadata.gz: 409e366b4c3d1fdfba0d331cea82b017d306a3518257398dd82b6ddb1bb9ac703a4c3620432ad4acee512f434d61db44651dc5117047f626def442076be56756
7
- data.tar.gz: 05bd6ec1d9c0a03c76609afc4f6c862019f3eb32b3299103887cee78af88f8938f06dc83a6cb6ac94d234cbad39e9a62203a993f30b6b72a04390dbd62830742
6
+ metadata.gz: 54b57b7d287df8fa95916abde5284658c2831588db59863166e8b54061067bde199e6338c251387f72434c1535924038db0a14739523904c3d2878112dc7069d
7
+ data.tar.gz: 4ec9fda62d8e9e2d74f7ef4db0b94c7e7d983797484d1cafd30911384bae9b1a9c9baa41de76cbe04e2704b1da1c38d201caca61e567e47684d6e765ce959f2f
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](http://keepachangelog.com/)
5
5
  and this project adheres to [Semantic Versioning](http://semver.org/).
6
6
 
7
+ ## 3.2.0 (2017-10-23)
8
+
9
+ - [enhancement] Make pool_size only configurable through configuration files
10
+
7
11
  ## 3.1.0 (2017-06-19)
8
12
 
9
13
  - [enhancement] Add support for erb syntax in database config file
data/README.md CHANGED
@@ -63,8 +63,8 @@ After this, your app should have access to all db tasks.
63
63
 
64
64
  ```sh
65
65
  $ rake -T
66
- rake db:create # Creates the database from DATABASE_URL or config/database.yml for the current RAILS_ENV (use db:create:all to create all ...
67
- rake db:drop # Drops the database from DATABASE_URL or config/database.yml for the current RAILS_ENV (use db:drop:all to drop all databa...
66
+ rake db:create # Creates the database from DATABASE_URL or config/database.yml for the current RACK_ENV (use db:create:all to create all ...
67
+ rake db:drop # Drops the database from DATABASE_URL or config/database.yml for the current RACK_ENV (use db:drop:all to drop all databa...
68
68
  rake db:environment:set # Set the environment value for the database
69
69
  rake db:fixtures:load # Loads fixtures into the current environment's database
70
70
  rake db:migrate # Migrate the database (options: VERSION=x, VERBOSE=false, SCOPE=blog)
@@ -28,28 +28,39 @@ module PhobosDBCheckpoint
28
28
  :phobos_db_checkpoint_
29
29
  end
30
30
 
31
- def configure(pool_size: nil)
32
- load_db_config(pool_size: pool_size)
31
+ def configure(options = {})
32
+ deprecate('options are deprecated, use configuration files instead') if options.keys.any?
33
+
34
+ load_db_config
33
35
  at_exit { PhobosDBCheckpoint.close_db_connection }
34
- ActiveRecord::Base.establish_connection(db_config)
36
+ PhobosDBCheckpoint.establish_db_connection
35
37
  end
36
38
 
37
39
  def env
38
40
  ENV['RAILS_ENV'] ||= ENV['RACK_ENV'] ||= 'development'
39
41
  end
40
42
 
41
- def load_db_config(pool_size: nil)
43
+ def load_db_config(options = {})
44
+ deprecate('options are deprecated, use configuration files instead') if options.keys.any?
45
+
42
46
  @db_config_path ||= ENV['DB_CONFIG'] || DEFAULT_DB_CONFIG_PATH
47
+
43
48
  configs = YAML.load(ERB.new(File.read(File.expand_path(@db_config_path))).result)
44
49
  @db_config = configs[env]
45
50
 
51
+ pool_size = @db_config['pool']
52
+
46
53
  if pool_size.nil? && Phobos.config
47
- pool_size = Phobos.config.listeners.map { |listener| listener.max_concurrency || 1 }.inject(&:+)
54
+ pool_size = number_of_concurrent_listeners + DEFAULT_POOL_SIZE
48
55
  end
49
56
 
50
57
  @db_config.merge!('pool' => pool_size || DEFAULT_POOL_SIZE)
51
58
  end
52
59
 
60
+ def establish_db_connection
61
+ ActiveRecord::Base.establish_connection(db_config)
62
+ end
63
+
53
64
  def close_db_connection
54
65
  ActiveRecord::Base.connection_pool.disconnect!
55
66
  rescue ActiveRecord::ConnectionNotEstablished
@@ -58,10 +69,19 @@ module PhobosDBCheckpoint
58
69
  def load_tasks
59
70
  @db_dir ||= DEFAULT_DB_DIR
60
71
  @migration_path ||= DEFAULT_MIGRATION_PATH
72
+
61
73
  ActiveRecord::Tasks::DatabaseTasks.send(:define_method, :db_dir) { PhobosDBCheckpoint.db_dir }
62
74
  ActiveRecord::Tasks::DatabaseTasks.send(:define_method, :migrations_paths) { [PhobosDBCheckpoint.migration_path] }
63
75
  ActiveRecord::Tasks::DatabaseTasks.send(:define_method, :env) { PhobosDBCheckpoint.env }
64
76
  require 'phobos_db_checkpoint/tasks'
65
77
  end
78
+
79
+ def number_of_concurrent_listeners
80
+ Phobos.config.listeners.map { |listener| listener.max_concurrency || 1 }.inject(&:+) || 0
81
+ end
82
+
83
+ def deprecate(message)
84
+ warn "DEPRECATION WARNING: #{message} #{Kernel.caller.first}"
85
+ end
66
86
  end
67
87
  end
@@ -44,7 +44,7 @@ module PhobosDBCheckpoint
44
44
  end
45
45
 
46
46
  unless active_connection?
47
- PhobosDBCheckpoint.configure(pool_size: 1)
47
+ PhobosDBCheckpoint.configure
48
48
  end
49
49
 
50
50
  destination_fullpath = File.join(destination_root, options[:destination])
@@ -1,11 +1,10 @@
1
1
  module PhobosDBCheckpoint
2
2
  module Middleware
3
3
  class Database
4
-
5
4
  def initialize(app, options = {})
6
5
  @app = app
7
- pool_size = options.fetch(:pool_size, PhobosDBCheckpoint::DEFAULT_POOL_SIZE)
8
- PhobosDBCheckpoint.configure(pool_size: pool_size)
6
+ PhobosDBCheckpoint.deprecate('options are deprecated, use configuration files instead') if options.keys.any?
7
+ PhobosDBCheckpoint.configure
9
8
  end
10
9
 
11
10
  def call(request_env)
@@ -11,7 +11,7 @@ module PhobosDBCheckpoint
11
11
 
12
12
  task :load_config do
13
13
  PhobosDBCheckpoint.load_db_config
14
- task_db_config = Hash[PhobosDBCheckpoint.env, PhobosDBCheckpoint.db_config.merge('pool' => 1)]
14
+ task_db_config = Hash[PhobosDBCheckpoint.env, PhobosDBCheckpoint.db_config]
15
15
  ActiveRecord::Tasks::DatabaseTasks.database_configuration = task_db_config
16
16
  end
17
17
  end
@@ -1,3 +1,3 @@
1
1
  module PhobosDBCheckpoint
2
- VERSION = '3.1.0'
2
+ VERSION = '3.2.0'
3
3
  end
@@ -8,10 +8,6 @@ logger_config = {
8
8
  # log_file: 'log/api.log'
9
9
  }
10
10
 
11
- database_config = {
12
- # pool_size: PhobosDBCheckpoint::DEFAULT_POOL_SIZE # 5
13
- }
14
-
15
11
  use PhobosDBCheckpoint::Middleware::Logger, logger_config
16
- use PhobosDBCheckpoint::Middleware::Database, database_config
12
+ use PhobosDBCheckpoint::Middleware::Database
17
13
  run PhobosDBCheckpoint::EventsAPI
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phobos_db_checkpoint
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Túlio Ornelas
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2017-06-20 00:00:00.000000000 Z
16
+ date: 2017-10-24 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: bundler