Class: Cubicle::Aggregation::CubicleMetadata

Inherits:
Object
  • Object
show all
Defined in:
lib/cubicle/aggregation/cubicle_metadata.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(aggregation) ⇒ CubicleMetadata

Returns a new instance of CubicleMetadata.



17
18
19
# File 'lib/cubicle/aggregation/cubicle_metadata.rb', line 17

def initialize(aggregation)
  @aggregation = aggregation
end

Instance Attribute Details

#aggregationObject (readonly)

Returns the value of attribute aggregation.



16
17
18
# File 'lib/cubicle/aggregation/cubicle_metadata.rb', line 16

def aggregation
  @aggregation
end

Class Method Details

.collectionObject



7
8
9
10
# File 'lib/cubicle/aggregation/cubicle_metadata.rb', line 7

def collection
  @@collection_name ||= "cubicle.metadata"
  Cubicle.mongo.database[@@collection_name]
end

.collection=(collection_name) ⇒ Object



11
12
13
# File 'lib/cubicle/aggregation/cubicle_metadata.rb', line 11

def collection=(collection_name)
  @@collection_name = collection_name
end

Instance Method Details

#aggregation_for(member_names = [], force = false) ⇒ Object



21
22
23
# File 'lib/cubicle/aggregation/cubicle_metadata.rb', line 21

def aggregation_for(member_names = [], force=false)
  AggregationMetadata.new(self,member_names,force)
end

#expire!(opts = {}) ⇒ Object



25
26
27
# File 'lib/cubicle/aggregation/cubicle_metadata.rb', line 25

def expire!(opts={})
  AggregationMetadata.expire(self,opts)
end

#unprotect_allObject



29
30
31
# File 'lib/cubicle/aggregation/cubicle_metadata.rb', line 29

def unprotect_all
  AggregationMetadata.unprotect_all(self)
end

#update_processing_statsObject



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
63
64
65
# File 'lib/cubicle/aggregation/cubicle_metadata.rb', line 33

def update_processing_stats
  Cubicle.logger.info "Processing #{aggregation.name} @ #{Time.now}"
  start = Time.now
  error = nil
  begin
    yield if block_given?
    Cubicle.logger.info "#{aggregation.name} processed @ #{Time.now}."
    result=:success
  rescue RuntimeError=>ex
    error = ex
    result = :error
    fail
  ensure
    stop = Time.now
    duration = stop - start
    stats = {:timestamp=>Time.now.utc,
             :aggregation=>aggregation.name,
             :last_duration_in_seconds=>duration,
             :result=>result
    }

    #If an error occurred, we want to record the message, but
    #not overwrite the timestamp of the last successful process.
    #If all was well, we want to indicate the now is the last
    #succesful processing of the aggregation.
    result == :error ? stats[:last_error] = error.inspect : stats[:last_processed]=stop

    self.class.collection.update({:aggregation=>aggregation.name},#criteria
                                 {"$set"=>stats},#data
                                 :upsert=>true)#upsert

  end
end