Class: MigrationExecution
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- MigrationExecution
- Defined in:
- app/models/migration_execution.rb
Instance Method Summary collapse
- #display_name ⇒ Object
-
#duration ⇒ Object
Instance methods.
-
#filter_params ⇒ Object
Custom getter for filter_params.
-
#filter_params=(value) ⇒ Object
Custom setter for filter_params.
- #progress_percentage ⇒ Object
-
#stats ⇒ Object
Custom getter for stats.
-
#stats=(value) ⇒ Object
Custom setter for stats.
Instance Method Details
#display_name ⇒ Object
38 39 40 |
# File 'app/models/migration_execution.rb', line 38 def display_name "#{execution_type.titleize} - #{migration_plan.name}" end |
#duration ⇒ Object
Instance methods
26 27 28 29 30 |
# File 'app/models/migration_execution.rb', line 26 def duration return nil unless started_at && completed_at completed_at - started_at end |
#filter_params ⇒ Object
Custom getter for filter_params
43 44 45 46 47 48 49 50 51 52 |
# File 'app/models/migration_execution.rb', line 43 def filter_params value = read_attribute(:filter_params) return {} if value.blank? return value if value.is_a?(Hash) JSON.parse(value) rescue JSON::ParserError => e Rails.logger.error "Failed to parse filter_params for MigrationExecution #{id}: #{e.}" {} end |
#filter_params=(value) ⇒ Object
Custom setter for filter_params
55 56 57 58 59 60 61 62 63 |
# File 'app/models/migration_execution.rb', line 55 def filter_params=(value) if value.is_a?(String) write_attribute(:filter_params, value) elsif value.is_a?(Hash) write_attribute(:filter_params, value.to_json) else write_attribute(:filter_params, {}.to_json) end end |
#progress_percentage ⇒ Object
32 33 34 35 36 |
# File 'app/models/migration_execution.rb', line 32 def progress_percentage return 0 if stats.blank? || stats['total'].to_i.zero? ((stats['processed'].to_f / stats['total']) * 100).round(2) end |
#stats ⇒ Object
Custom getter for stats
66 67 68 69 70 71 72 73 74 75 |
# File 'app/models/migration_execution.rb', line 66 def stats value = read_attribute(:stats) return {} if value.blank? return value if value.is_a?(Hash) JSON.parse(value) rescue JSON::ParserError => e Rails.logger.error "Failed to parse stats for MigrationExecution #{id}: #{e.}" {} end |
#stats=(value) ⇒ Object
Custom setter for stats
78 79 80 81 82 83 84 85 86 |
# File 'app/models/migration_execution.rb', line 78 def stats=(value) if value.is_a?(String) write_attribute(:stats, value) elsif value.is_a?(Hash) write_attribute(:stats, value.to_json) else write_attribute(:stats, {}.to_json) end end |