Class: Harmonia::Sync
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Harmonia::Sync
- Defined in:
- lib/generators/harmonia/templates/harmonia_sync.rb
Class Method Summary collapse
-
.last_sync_for(table_name, direction) ⇒ Object
Get the most recent successful sync for a table in a given direction.
Instance Method Summary collapse
-
#complete? ⇒ Boolean
Check if sync was complete.
-
#completion_percentage ⇒ Object
Calculate sync completion percentage.
-
#fail!(error_message, failed_fm_ids: {}, failed_pg_ids: {}) ⇒ Object
Mark sync as failed.
-
#finish!(records_synced:, records_required:, failed_fm_ids: {}, failed_pg_ids: {}) ⇒ Object
Mark sync as completed.
-
#start! ⇒ Object
Mark sync as started.
Methods inherited from ApplicationRecord
Class Method Details
.last_sync_for(table_name, direction) ⇒ Object
Get the most recent successful sync for a table in a given direction
28 29 30 |
# File 'lib/generators/harmonia/templates/harmonia_sync.rb', line 28 def self.last_sync_for(table_name, direction) completed.for_direction(direction).for_table(table_name).recent.first end |
Instance Method Details
#complete? ⇒ Boolean
Check if sync was complete
39 40 41 |
# File 'lib/generators/harmonia/templates/harmonia_sync.rb', line 39 def complete? status == 'completed' && records_synced == records_required end |
#completion_percentage ⇒ Object
Calculate sync completion percentage
33 34 35 36 |
# File 'lib/generators/harmonia/templates/harmonia_sync.rb', line 33 def completion_percentage return 0 if records_required.to_i.zero? ((records_synced.to_f / records_required.to_f) * 100).round(2) end |
#fail!(error_message, failed_fm_ids: {}, failed_pg_ids: {}) ⇒ Object
Mark sync as failed
61 62 63 64 65 66 67 68 |
# File 'lib/generators/harmonia/templates/harmonia_sync.rb', line 61 def fail!(, failed_fm_ids: {}, failed_pg_ids: {}) update!( status: 'failed', error_message: , failed_fm_ids: failed_fm_ids, failed_pg_ids: failed_pg_ids ) end |
#finish!(records_synced:, records_required:, failed_fm_ids: {}, failed_pg_ids: {}) ⇒ Object
Mark sync as completed
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/generators/harmonia/templates/harmonia_sync.rb', line 49 def finish!(records_synced:, records_required:, failed_fm_ids: {}, failed_pg_ids: {}) status = records_synced == records_required ? 'completed' : 'failed' update!( status: status, records_synced: records_synced, records_required: records_required, failed_fm_ids: failed_fm_ids, failed_pg_ids: failed_pg_ids ) end |
#start! ⇒ Object
Mark sync as started
44 45 46 |
# File 'lib/generators/harmonia/templates/harmonia_sync.rb', line 44 def start! update!(status: 'in_progress') end |