4233: make the log replay helper deal with the old date format
authorPhil Hodgson <bitbucket@philhodgson.net>
Thu, 20 Nov 2014 17:19:39 +0000 (18:19 +0100)
committerPhil Hodgson <bitbucket@philhodgson.net>
Thu, 20 Nov 2014 17:19:39 +0000 (18:19 +0100)
services/api/lib/simulate_job_log.rb

index a0ab28d246aad26042a397bda3eedb56e9e7933a..71c9825e44357f221297eb81c165f9c0ba1d6046 100644 (file)
@@ -11,8 +11,19 @@ module SimulateJobLog
                act_as_system_user do
                        File.open(filename).each.with_index do |line, index|
                                cols = {}
-                       cols[:timestamp], cols[:job_uuid], cols[:pid], cols[:task], cols[:event_type], cols[:message] = line.split(' ', 6)
-                       cols[:timestamp] = Time.strptime( cols[:timestamp], "%Y-%m-%d_%H:%M:%S" )
+                       cols[:timestamp], rest_of_line = line.split(' ', 2)
+                       begin
+                               cols[:timestamp] = Time.strptime( cols[:timestamp], "%Y-%m-%d_%H:%M:%S" )
+                       rescue ArgumentError
+                               if line =~ /^((?:Sun|Mon|Tue|Wed|Thu|Fri|Sat) (?:Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) \d{1,2} \d\d:\d\d:\d\d \d{4}) (.*)/
+                                       # Wed Nov 19 07:12:39 2014
+                                       cols[:timestamp] = Time.strptime( $1, "%a %b %d %H:%M:%S %Y" )
+                                       rest_of_line = $2
+                               else
+                                       STDERR.puts "Ignoring log line because of unknown time format: #{line}"
+                               end
+                       end
+                       cols[:job_uuid], cols[:pid], cols[:task], cols[:event_type], cols[:message] = rest_of_line.split(' ', 5)
                        # Override job uuid with a simulated one if specified
                        cols[:job_uuid] = simulated_job_uuid || cols[:job_uuid]
                        # determine when we want to simulate this log being created, based on the time multiplier