module Isimud::ModelWatcher::ClassMethods
Public Instance Methods
# File lib/isimud/model_watcher.rb, line 72 def isimud_model_watcher_type (respond_to?(:base_class) ? base_class.name : name).demodulize end
Include the following tables when fetching records for synchronization
# File lib/isimud/model_watcher.rb, line 37 def sync_include(_sync_includes) self.sync_includes = _sync_includes end
Synchronize instances of this model with the data warehouse. This is accomplished by calling isimud_notify_updated() on each instance fetched from the database. @param [Hash] options synchronize options @option options [ActiveRecord::Relation] :where where_clause filter for limiting records to sync. By default, all records are synchronized. @option options [IO] :output optional stream for writing progress. A '.' is printed for every 100 records synchronized. @return [Integer] number of records synchronized
# File lib/isimud/model_watcher.rb, line 47 def synchronize(options = {}) where_clause = options[:where] || {} output = options[:output] || nil count = 0 query = self.where(where_clause) query = query.includes(sync_includes) if sync_includes query.find_each do |m| next unless m.isimud_synchronize? begin m.isimud_sync rescue Bunny::ClientTimeout, Timeout::Error => e output && output.print("\n#{e}, sleeping for 10 seconds") sleep(10) m.isimud_sync end if (count += 1) % 100 == 0 output && output.print('.') end if (count % 1000) == 0 GC.start end end count end
Set attributes to observe and include in messages. Any property method with a return value may be included in the list of attributes. @param [Array<String,Symbol>] attributes list of attributes / properties
# File lib/isimud/model_watcher.rb, line 32 def watch_attributes(*attributes) self.isimud_watch_attributes = attributes.flatten.map(&:to_s) if attributes.present? end