Class: UsageTracker
- Inherits:
-
Object
- Object
- UsageTracker
- Defined in:
- lib/quartz_flow/usagetracker.rb
Instance Method Summary collapse
-
#allUsage(periodType) ⇒ Object
Returns the usage as of the last time update() was called.
-
#currentUsage(periodType) ⇒ Object
This method returns the usage in the current bucket for the specified period type (:daily or :monthly).
-
#initialize(monthlyResetDay) ⇒ UsageTracker
constructor
A new instance of UsageTracker.
-
#update(usageForAllTime) ⇒ Object
Update the UsageTracker with more usage.
Constructor Details
#initialize(monthlyResetDay) ⇒ UsageTracker
Returns a new instance of UsageTracker.
215 216 217 218 219 220 221 222 |
# File 'lib/quartz_flow/usagetracker.rb', line 215 def initialize(monthlyResetDay) @buckets = {} @buckets[:daily] = PeriodicBuckets.new(DailyBucketChangeCriteria.new,31) #@buckets[:minute] = PeriodicBuckets.new(MinuteBucketChangeCriteria.new,3) @buckets[:monthly] = PeriodicBuckets.new(MonthlyBucketChangeCriteria.new(monthlyResetDay),2) @usageForAllTimeAdjustment = 0 loadBucketsFromDatastore end |
Instance Method Details
#allUsage(periodType) ⇒ Object
Returns the usage as of the last time update() was called. This method returns all the tracked usage for the specified period type (:daily or :monthly). The usage is accurate as of the last time update() was called. The returned value is an array of Bucket objects.
251 252 253 |
# File 'lib/quartz_flow/usagetracker.rb', line 251 def allUsage(periodType) getBuckets(periodType).all end |
#currentUsage(periodType) ⇒ Object
This method returns the usage in the current bucket for the specified period type (:daily or :monthly). The usage is accurate as of the last time update() was called. The returned value is a single Bucket object.
242 243 244 |
# File 'lib/quartz_flow/usagetracker.rb', line 242 def currentUsage(periodType) getBuckets(periodType).current end |
#update(usageForAllTime) ⇒ Object
Update the UsageTracker with more usage. The value passed should be the usage since the torrentflow session was created. If a datastore is not used, then this means stopping and starting the session will cause UsageTracking to only track usage for the session. However if Mongo is used then the usage can be saved and persisted between sessions and internally the value passed here is added to the value loaded from Mongo.
230 231 232 233 234 235 236 |
# File 'lib/quartz_flow/usagetracker.rb', line 230 def update(usageForAllTime) usageForAllTime += @usageForAllTimeAdjustment @buckets.each do |k,buckets| buckets.update usageForAllTime end saveBucketsToDatastore end |