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'.freeze
- DEFAULT_MIGRATION_PATH =
File.join(DEFAULT_DB_DIR, 'migrate').freeze
- DEFAULT_DB_CONFIG_PATH =
'config/database.yml'.freeze
- DEFAULT_POOL_SIZE =
5.freeze
- VERSION =
'3.3.0'
Class Attribute Summary collapse
Class Method Summary
collapse
Class Attribute Details
.db_config ⇒ Object
Returns the value of attribute db_config.
22
23
24
|
# File 'lib/phobos_db_checkpoint.rb', line 22
def db_config
@db_config
end
|
.db_config_path ⇒ Object
Returns the value of attribute db_config_path.
23
24
25
|
# File 'lib/phobos_db_checkpoint.rb', line 23
def db_config_path
@db_config_path
end
|
.db_dir ⇒ Object
Returns the value of attribute db_dir.
23
24
25
|
# File 'lib/phobos_db_checkpoint.rb', line 23
def db_dir
@db_dir
end
|
.migration_path ⇒ Object
Returns the value of attribute migration_path.
23
24
25
|
# File 'lib/phobos_db_checkpoint.rb', line 23
def migration_path
@migration_path
end
|
Class Method Details
.close_db_connection ⇒ Object
64
65
66
67
|
# File 'lib/phobos_db_checkpoint.rb', line 64
def close_db_connection
ActiveRecord::Base.connection_pool.disconnect!
rescue ActiveRecord::ConnectionNotEstablished
end
|
31
32
33
34
35
36
37
|
# File 'lib/phobos_db_checkpoint.rb', line 31
def configure(options = {})
deprecate('options are deprecated, use configuration files instead') if options.keys.any?
load_db_config
at_exit { PhobosDBCheckpoint.close_db_connection }
PhobosDBCheckpoint.establish_db_connection
end
|
.deprecate(message) ⇒ Object
83
84
85
|
# File 'lib/phobos_db_checkpoint.rb', line 83
def deprecate(message)
warn "DEPRECATION WARNING: #{message} #{Kernel.caller.first}"
end
|
.env ⇒ Object
39
40
41
|
# File 'lib/phobos_db_checkpoint.rb', line 39
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/phobos_db_checkpoint.rb', line 43
def load_db_config(options = {})
deprecate('options are deprecated, use configuration files instead') if options.keys.any?
@db_config_path ||= ENV['DB_CONFIG'] || DEFAULT_DB_CONFIG_PATH
configs = YAML.load(ERB.new(File.read(File.expand_path(@db_config_path))).result)
@db_config = configs[env]
pool_size = @db_config['pool']
if pool_size.nil? && Phobos.config
pool_size = number_of_concurrent_listeners + DEFAULT_POOL_SIZE
end
@db_config.merge!('pool' => pool_size || DEFAULT_POOL_SIZE)
end
|
.load_tasks ⇒ Object
69
70
71
72
73
74
75
76
77
|
# File 'lib/phobos_db_checkpoint.rb', line 69
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
79
80
81
|
# File 'lib/phobos_db_checkpoint.rb', line 79
def number_of_concurrent_listeners
Phobos.config.listeners.map { |listener| listener.max_concurrency || 1 }.inject(&:+) || 0
end
|
.table_name_prefix ⇒ Object
:nodoc: ActiveRecord hook
27
28
29
|
# File 'lib/phobos_db_checkpoint.rb', line 27
def table_name_prefix
:phobos_db_checkpoint_
end
|