Module: Fiveruns::Dash::Store::Mongo

Included in:
FiverunsDashUpdateExtensions
Defined in:
lib/dash_analyzer/dash_extensions.rb

Overview

Setup a store_mongo method on Fiveruns::Dash::Store NOTE: I think there is a better way to do this

Instance Method Summary collapse

Instance Method Details

#store_mongo(*uris) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/dash_analyzer/dash_extensions.rb', line 24

def store_mongo(*uris)    
  Fiveruns::Dash.logger.info "Attempting to send #{payload.class}"

  if payload.is_a? Fiveruns::Dash::DataPayload
    data = payload.data

    data.each do |d|
      recipe_name = d[:recipe_name]
      name = d[:name]
      storage_name = "#{recipe_name}-#{name}"
      d[:created_at] = Time.now
      
      # TODO: Use upsert to handle cluser wide implementations
      Fiveruns::Dash.session.configuration.db.collection(storage_name).insert(d)
      Fiveruns::Dash.logger.info "Sent #{payload.class} to #{Fiveruns::Dash.session.configuration.db}"
    end
  else
    raise "Payload of type #{payload.class} Not Currently Supported"
  end
rescue
  Fiveruns::Dash.logger.warn "Could not send #{payload.class}: #{$!}"
end