Module: PhobosDBCheckpoint
- Defined in:
- lib/phobos_db_checkpoint.rb,
lib/phobos_db_checkpoint/cli.rb,
lib/phobos_db_checkpoint/event.rb,
lib/phobos_db_checkpoint/tasks.rb,
lib/phobos_db_checkpoint/errors.rb,
lib/phobos_db_checkpoint/failure.rb,
lib/phobos_db_checkpoint/handler.rb,
lib/phobos_db_checkpoint/version.rb,
lib/phobos_db_checkpoint/events_api.rb,
lib/phobos_db_checkpoint/event_helper.rb,
lib/phobos_db_checkpoint/event_actions.rb,
lib/phobos_db_checkpoint/middleware/logger.rb,
lib/phobos_db_checkpoint/middleware/database.rb,
lib/phobos_db_checkpoint/actions/retry_failure.rb
Defined Under Namespace
Modules: CLI, EventHelper, Handler, Middleware, Tasks Classes: Ack, Event, EventsAPI, Failure, ListenerNotFoundError, PhobosDBCheckpointError, RetryFailure
Constant Summary collapse
- DEFAULT_DB_DIR =
'db'
- DEFAULT_MIGRATION_PATH =
File.join(DEFAULT_DB_DIR, 'migrate').freeze
- DEFAULT_DB_CONFIG_PATH =
'config/database.yml'
- DEFAULT_POOL_SIZE =
5
- VERSION =
'3.4.0'
Class Attribute Summary collapse
-
.db_config ⇒ Object
readonly
Returns the value of attribute db_config.
-
.db_config_path ⇒ Object
Returns the value of attribute db_config_path.
-
.db_dir ⇒ Object
Returns the value of attribute db_dir.
-
.migration_path ⇒ Object
Returns the value of attribute migration_path.
Class Method Summary collapse
-
.close_db_connection ⇒ Object
rubocop:disable Lint/HandleExceptions.
- .configure(options = {}) ⇒ Object
- .deprecate(message) ⇒ Object
- .env ⇒ Object
- .establish_db_connection ⇒ Object
- .load_db_config(options = {}) ⇒ Object
-
.load_tasks ⇒ Object
rubocop:enable Lint/HandleExceptions.
- .number_of_concurrent_listeners ⇒ Object
-
.table_name_prefix ⇒ Object
:nodoc: ActiveRecord hook.
Class Attribute Details
.db_config ⇒ Object (readonly)
Returns the value of attribute db_config.
24 25 26 |
# File 'lib/phobos_db_checkpoint.rb', line 24 def db_config @db_config end |
.db_config_path ⇒ Object
Returns the value of attribute db_config_path.
25 26 27 |
# File 'lib/phobos_db_checkpoint.rb', line 25 def db_config_path @db_config_path end |
.db_dir ⇒ Object
Returns the value of attribute db_dir.
25 26 27 |
# File 'lib/phobos_db_checkpoint.rb', line 25 def db_dir @db_dir end |
.migration_path ⇒ Object
Returns the value of attribute migration_path.
25 26 27 |
# File 'lib/phobos_db_checkpoint.rb', line 25 def migration_path @migration_path end |
Class Method Details
.close_db_connection ⇒ Object
rubocop:disable Lint/HandleExceptions
65 66 67 68 |
# File 'lib/phobos_db_checkpoint.rb', line 65 def close_db_connection ActiveRecord::Base.connection_pool.disconnect! rescue ActiveRecord::ConnectionNotEstablished end |
.configure(options = {}) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/phobos_db_checkpoint.rb', line 33 def configure( = {}) deprecate('options are deprecated, use configuration files instead') if .keys.any? load_db_config at_exit { PhobosDBCheckpoint.close_db_connection } PhobosDBCheckpoint.establish_db_connection end |
.deprecate(message) ⇒ Object
85 86 87 |
# File 'lib/phobos_db_checkpoint.rb', line 85 def deprecate() warn "DEPRECATION WARNING: #{} #{Kernel.caller.first}" end |
.env ⇒ Object
41 42 43 |
# File 'lib/phobos_db_checkpoint.rb', line 41 def env ENV['RAILS_ENV'] ||= ENV['RACK_ENV'] ||= 'development' end |
.establish_db_connection ⇒ Object
60 61 62 |
# File 'lib/phobos_db_checkpoint.rb', line 60 def establish_db_connection ActiveRecord::Base.establish_connection(db_config) end |
.load_db_config(options = {}) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/phobos_db_checkpoint.rb', line 45 def load_db_config( = {}) deprecate('options are deprecated, use configuration files instead') if .keys.any? @db_config_path ||= ENV['DB_CONFIG'] || DEFAULT_DB_CONFIG_PATH configs = YAML.safe_load(ERB.new(File.read(File.(@db_config_path))).result, [], [], true) @db_config = configs[env] pool_size = @db_config['pool'] pool_size = number_of_concurrent_listeners + DEFAULT_POOL_SIZE if pool_size.nil? && Phobos.config @db_config.merge!('pool' => pool_size || DEFAULT_POOL_SIZE) end |
.load_tasks ⇒ Object
rubocop:enable Lint/HandleExceptions
71 72 73 74 75 76 77 78 79 |
# File 'lib/phobos_db_checkpoint.rb', line 71 def load_tasks @db_dir ||= DEFAULT_DB_DIR @migration_path ||= DEFAULT_MIGRATION_PATH ActiveRecord::Tasks::DatabaseTasks.send(:define_method, :db_dir) { PhobosDBCheckpoint.db_dir } ActiveRecord::Tasks::DatabaseTasks.send(:define_method, :migrations_paths) { [PhobosDBCheckpoint.migration_path] } ActiveRecord::Tasks::DatabaseTasks.send(:define_method, :env) { PhobosDBCheckpoint.env } require 'phobos_db_checkpoint/tasks' end |
.number_of_concurrent_listeners ⇒ Object
81 82 83 |
# File 'lib/phobos_db_checkpoint.rb', line 81 def number_of_concurrent_listeners Phobos.config.listeners.map { |listener| listener.max_concurrency || 1 }.inject(&:+) || 0 end |
.table_name_prefix ⇒ Object
:nodoc: ActiveRecord hook
29 30 31 |
# File 'lib/phobos_db_checkpoint.rb', line 29 def table_name_prefix :phobos_db_checkpoint_ end |