Class: Backup::MoveLogs
- Inherits:
-
Object
- Object
- Backup::MoveLogs
- Defined in:
- lib/backup/move_logs.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
-
#initialize(config, db_helper, dry_run_reporter = nil) ⇒ MoveLogs
constructor
A new instance of MoveLogs.
- #process_logs_batch(logs_batch) ⇒ Object
- #run ⇒ Object
- #run_dry ⇒ Object
Constructor Details
#initialize(config, db_helper, dry_run_reporter = nil) ⇒ MoveLogs
Returns a new instance of MoveLogs.
7 8 9 10 11 |
# File 'lib/backup/move_logs.rb', line 7 def initialize(config, db_helper, dry_run_reporter=nil) @config = config @dry_run_reporter = dry_run_reporter @db_helper = db_helper end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
5 6 7 |
# File 'lib/backup/move_logs.rb', line 5 def config @config end |
Instance Method Details
#process_logs_batch(logs_batch) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/backup/move_logs.rb', line 22 def process_logs_batch(logs_batch) log_hashes = logs_batch.as_json @db_helper.connect_db(@config.destination_db_url) log_hashes.each do |log_hash| new_log = Log.new(log_hash) new_log.save! end @db_helper.connect_db(@config.database_url) logs_batch.each(&:destroy) GC.start end |
#run ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/backup/move_logs.rb', line 13 def run return run_dry if @config.dry_run @db_helper.connect_db(@config.database_url) Log.order(:id).in_batches(of: @config.limit.to_i).map do |logs_batch| process_logs_batch(logs_batch) end end |
#run_dry ⇒ Object
38 39 40 41 |
# File 'lib/backup/move_logs.rb', line 38 def run_dry ids = Log.order(:id).map(&:id) @dry_run_reporter.add_to_report(:logs, *ids) end |