lib/tabs/metrics/task.rb in tabs-0.6.3 vs lib/tabs/metrics/task.rb in tabs-0.7.0
- old
+ new
@@ -10,17 +10,17 @@
def initialize(key)
@key = key
end
- def start(token)
- Token.new(token, key).start
+ def start(token, timestamp=Time.now)
+ Token.new(token, key).start(timestamp)
true
end
- def complete(token)
- Token.new(token, key).complete
+ def complete(token, timestamp=Time.now)
+ Token.new(token, key).complete(timestamp)
true
end
def stats(period, resolution)
range = timestamp_range(period, resolution)
@@ -44,11 +44,18 @@
end
private
def tokens_for_period(range, resolution, type)
- keys = Task::Token.keys_for_range(key, range, resolution, type)
+ keys = keys_for_range(range, resolution, type)
mget(*keys).compact.map(&:to_a).flatten.map { |t| Token.new(t, key) }
+ end
+
+ def keys_for_range(range, resolution, type)
+ range.map do |date|
+ formatted_time = Tabs::Resolution.serialize(resolution, date)
+ "stat:task:#{key}:#{type}:#{formatted_time}"
+ end
end
end
end
end