lib/onering/plugins/reporter.rb in onering-client-0.1.6 vs lib/onering/plugins/reporter.rb in onering-client-0.1.7
- old
+ new
@@ -211,14 +211,16 @@
if options[:cacheregen] == true
Onering::Logger.debug("Forcing cache regeneration", "Onering::Reporter")
cache = _update_cache_file(cachefile)
end
- # remove cached_at key
- Onering::Logger.debug("Using cached data (#{Time.now.to_i - Time.parse(cache.get('cached_at')).to_i} seconds old)", "Onering::Reporter")
- cache.delete('cached_at')
- return cache
+ if cache
+ # remove cached_at key
+ Onering::Logger.debug("Using cached data (#{Time.now.to_i - Time.parse(cache.get('cached_at')).to_i} seconds old)", "Onering::Reporter")
+ cache.delete('cached_at')
+ return cache
+ end
else
Onering::Logger.debug("Report cache file could not be read at #{cachefile}", "Onering::Reporter")
throw :retry if _update_cache_file(cachefile)
end
end
@@ -228,10 +230,10 @@
def _update_cache_file(cachefile=DEFAULT_CACHE_FILE)
begin
report = nil
-
+
File.open(cachefile, 'w+') do |file|
Onering::Logger.debug("Regenerating cache file at #{cachefile}", "Onering::Reporter")
report = _generated_report()
report['cached_at'] = Time.now.strftime('%Y-%m-%dT%H:%M:%S%z')
json = MultiJson.dump(report, :pretty => true)