Class: KMDB::Jobs::RecordBatch
- Defined in:
- lib/kmdb/jobs/record_batch.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(id) ⇒ RecordBatch
constructor
A new instance of RecordBatch.
- #work ⇒ Object
Constructor Details
#initialize(id) ⇒ RecordBatch
Returns a new instance of RecordBatch.
23 24 25 26 |
# File 'lib/kmdb/jobs/record_batch.rb', line 23 def initialize(id) @batch = EventBatch.find(id) raise ArgumentError.new('no such batch') if @batch.nil? end |
Class Method Details
.perform(id) ⇒ Object
19 20 21 |
# File 'lib/kmdb/jobs/record_batch.rb', line 19 def self.perform(id) new(id).work end |
Instance Method Details
#work ⇒ Object
28 29 30 31 32 33 34 35 36 37 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 |
# File 'lib/kmdb/jobs/record_batch.rb', line 28 def work event_sql = [] properties_sql = [] @batch.events.each do |event| # reject non-whitelisted events next unless event['_n'].nil? || WhitelistedEvent.include?(event['_n']) # reject ignored users next if IgnoredUser.include?(event['_p']) || IgnoredUser.include?(event['_p2']) # store depending on event type if event['_p2'] # ignore aliasing between "real" users next if event['_p'] =~ /^\d+$/ && event['_p2'] =~ /^\d+$/ aliaz = Alias.record event['_p'], event['_p2'], event['_t'] Resque.enqueue(UnaliasUser, aliaz.name1, aliaz.name2) elsif event['_n'] Event.sql_for(event) do |e,p| event_sql << e properties_sql << p end else properties_sql << Property.sql_for(event) end end KMDB.transaction do |c| Event.mass_create(event_sql.compact) Property.mass_create(properties_sql.compact) end @batch.delete end |