whimsical-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Sebastian Bazley <s...@apache.org>
Subject [whimsy.git] [1/1] Commit b9f3eda: Archive failed log files
Date Tue, 23 Feb 2016 00:38:49 GMT
Commit b9f3eda85cf1bab2f94d713574c02a804005db5e:
    Archive failed log files


Branch: refs/heads/master
Author: Sebb <sebb@apache.org>
Committer: Sebb <sebb@apache.org>
Pusher: sebb <sebb@apache.org>

------------------------------------------------------------
www/status/monitors/public_json.rb                           | ++++++++++ --
------------------------------------------------------------
23 changes: 20 additions, 3 deletions.
------------------------------------------------------------


diff --git a/www/status/monitors/public_json.rb b/www/status/monitors/public_json.rb
index f25c7c0..fb56319 100644
--- a/www/status/monitors/public_json.rb
+++ b/www/status/monitors/public_json.rb
@@ -2,19 +2,25 @@
 # Monitor status of public json directory
 #
 
+require 'fileutils'
+
 def Monitor.public_json(previous_status)
   danger_period = 86_400 # one day
 
   warning_period = 5400 # 1.5 hours
 
-  logs = File.expand_path('../../www/logs/public-*')
+  logdir = File.expand_path('../../www/logs')
+  logs = File.join(logdir, 'public-*')
+
+  archive = File.join(logdir,'archive')
+  FileUtils.mkdir(archive) unless File.directory?(archive)
 
   status = {}
 
   Dir[logs].each do |log|
-    begin
-      name = File.basename(log).sub('public-', '')
+    name = File.basename(log).sub('public-', '')
 
+    begin
       status[name] = {
         href: "../logs/#{File.basename(log)}",
         mtime: File.mtime(log)
@@ -69,7 +75,18 @@ def Monitor.public_json(previous_status)
         }
       }
     end
+
+    if status[name][:level]
+      FileUtils.copy log, archive,
+        preserve: true
+    end
   end
 
   {data: status}
 end
+
+# for debugging purposes
+if __FILE__ == $0
+  require 'json'
+  puts JSON.pretty_generate(Monitor.public_json(nil))
+end

Mime
View raw message