Merge branch '8784-dir-listings'
[arvados.git] / services / api / lib / simulate_job_log.rb
index fc124c8f7770353d6d797e7d2c7cdf5fcffde4b3..abcf42eaa708594164214611eabe3a07c0e47b2f 100644 (file)
@@ -1,4 +1,11 @@
+# Copyright (C) The Arvados Authors. All rights reserved.
+#
+# SPDX-License-Identifier: AGPL-3.0
+
+require 'current_api_client'
+
 module SimulateJobLog
+  include CurrentApiClient
   def replay(filename, multiplier = 1, simulated_job_uuid = nil)
     raise "Environment must be development or test" unless [ 'test', 'development' ].include? ENV['RAILS_ENV']
 
@@ -8,6 +15,12 @@ module SimulateJobLog
     actual_start_time = Time.now
     log_start_time = nil
 
+    if simulated_job_uuid and (job = Job.where(uuid: simulated_job_uuid).first)
+      job_owner_uuid = job.owner_uuid
+    else
+      job_owner_uuid = system_user_uuid
+    end
+
     act_as_system_user do
       File.open(filename).each.with_index do |line, index|
         cols = {}
@@ -34,9 +47,9 @@ module SimulateJobLog
         modified_elapsed_time = log_elapsed_time / multiplier
         pause_time = modified_elapsed_time - actual_elapsed_time
         sleep pause_time if pause_time > 0
-        # output log entry for debugging and create it in the current environment's database
-        puts "#{index} #{cols.to_yaml}\n"
+
         Log.new({
+          owner_uuid:  job_owner_uuid,
           event_at:    Time.zone.local_to_utc(cols[:timestamp]),
           object_uuid: cols[:job_uuid],
           event_type:  cols[:event_type],