Class: Jason::ConsistencyChecker
- Inherits:
-
Object
- Object
- Jason::ConsistencyChecker
- Defined in:
- lib/jason/consistency_checker.rb
Instance Attribute Summary collapse
-
#inconsistent ⇒ Object
readonly
Returns the value of attribute inconsistent.
-
#subscription ⇒ Object
readonly
Returns the value of attribute subscription.
Class Method Summary collapse
Instance Method Summary collapse
-
#check ⇒ Object
Take a subscription, get the current cached payload, and compare it to the data retrieved from the database.
- #inconsistent? ⇒ Boolean
-
#initialize(subscription) ⇒ ConsistencyChecker
constructor
A new instance of ConsistencyChecker.
- #wipe_all_subs ⇒ Object
Constructor Details
#initialize(subscription) ⇒ ConsistencyChecker
Returns a new instance of ConsistencyChecker.
28 29 30 31 |
# File 'lib/jason/consistency_checker.rb', line 28 def initialize(subscription) @subscription = subscription @inconsistent = false end |
Instance Attribute Details
#inconsistent ⇒ Object (readonly)
Returns the value of attribute inconsistent.
3 4 5 |
# File 'lib/jason/consistency_checker.rb', line 3 def inconsistent @inconsistent end |
#subscription ⇒ Object (readonly)
Returns the value of attribute subscription.
2 3 4 |
# File 'lib/jason/consistency_checker.rb', line 2 def subscription @subscription end |
Class Method Details
.check_all(fix: false) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/jason/consistency_checker.rb', line 5 def self.check_all(fix: false) Jason::Subscription.all.each do |sub| next if sub.consumer_count == 0 checker = Jason::ConsistencyChecker.new(sub) result = checker.check if checker.inconsistent? pp sub.config pp result if fix sub.reset!(hard: true) end end end end |
.fix_all ⇒ Object
20 21 22 |
# File 'lib/jason/consistency_checker.rb', line 20 def self.fix_all check_all(fix: true) end |
Instance Method Details
#check ⇒ Object
Take a subscription, get the current cached payload, and compare it to the data retrieved from the database
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/jason/consistency_checker.rb', line 38 def check cached_payload = subscription.get edge_set = subscription.load_ids_for_sub_models(subscription.model, nil) result = cached_payload.map do |model_name, data| cached_payload_instance_ids = data[:payload].map { |row| row['id'] } model_idx = edge_set[:model_names].index(model_name) if model_idx.present? edge_set_instance_ids = edge_set[:instance_ids].map { |row| row[model_idx] } else next end missing = edge_set_instance_ids - cached_payload_instance_ids intruding = cached_payload_instance_ids - edge_set_instance_ids if missing.present? || intruding.present? @inconsistent = true end [model_name, { 'missing' => missing, 'intruding' => intruding }] end.compact.to_h end |
#inconsistent? ⇒ Boolean
33 34 35 |
# File 'lib/jason/consistency_checker.rb', line 33 def inconsistent? inconsistent end |
#wipe_all_subs ⇒ Object
24 25 26 |
# File 'lib/jason/consistency_checker.rb', line 24 def wipe_all_subs end |