[ARVADOS] created: 73c02220c31cd631b75b707d93709c8a60c21207
git at public.curoverse.com
git at public.curoverse.com
Wed Nov 12 07:40:35 EST 2014
at 73c02220c31cd631b75b707d93709c8a60c21207 (commit)
commit 73c02220c31cd631b75b707d93709c8a60c21207
Author: Phil Hodgson <bitbucket at philhodgson.net>
Date: Wed Nov 12 13:40:22 2014 +0100
4233: "helper" method for replaying a job log from a specified file, with utility rake task
diff --git a/services/api/lib/simulate_job_log.rb b/services/api/lib/simulate_job_log.rb
new file mode 100644
index 0000000..cfcc8ab
--- /dev/null
+++ b/services/api/lib/simulate_job_log.rb
@@ -0,0 +1,40 @@
+module SimulateJobLog
+ def replay(filename, simulated_job_uuid = nil, multiplier = 1)
+ raise "Environment must be development or test" unless [ 'test', 'development' ].include? ENV['RAILS_ENV']
+
+ multiplier = multiplier.to_f
+ multiplier = 1.0 if multiplier <= 0
+
+ actual_start_time = Time.now
+ log_start_time = nil
+
+ 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" )
+ # 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
+ log_start_time = cols[:timestamp] if log_start_time.nil?
+ log_time = cols[:timestamp]
+ actual_elapsed_time = Time.now - actual_start_time
+ log_elapsed_time = log_time - log_start_time
+ modified_elapsed_time = log_elapsed_time / multiplier
+ pause_time = modified_elapsed_time - actual_elapsed_time
+ if pause_time > 0
+ sleep pause_time
+ end
+ # output log entry for debugging and create it in the current environment's database
+ puts "#{index} #{cols.to_yaml}\n"
+ Log.new({
+ event_at: Time.zone.local_to_utc(cols[:timestamp]),
+ object_uuid: cols[:job_uuid],
+ event_type: cols[:event_type],
+ properties: { 'text' => cols[:message] }
+ }).save!
+ end
+ end
+
+ end
+end
diff --git a/services/api/lib/tasks/replay_job_log.rake b/services/api/lib/tasks/replay_job_log.rake
new file mode 100644
index 0000000..59b75fa
--- /dev/null
+++ b/services/api/lib/tasks/replay_job_log.rake
@@ -0,0 +1,7 @@
+require 'simulate_job_log'
+desc 'Simulate job logging from a file. Three arguments: log filename, simulated job uuid (optional), time multipler (optional). E.g. (note quotation marks): rake "replay_job_log[log.txt, qr1hi-8i9sb-nf3qk0xzwwz3lre, 2.0]"'
+task :replay_job_log, [:filename, :uuid, :multiplier] => :environment do |t, args|
+ include SimulateJobLog
+ abort("No filename specified.") if args[:filename].blank?
+ replay( args[:filename], args[:uuid], args[:multiplier].to_f )
+end
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list