[ARVADOS] updated: b5c40a0304a9de42ae0ed3d0517e1365552c0e04

git at public.curoverse.com git at public.curoverse.com
Mon Mar 16 19:07:43 EDT 2015


Summary of changes:
 services/api/app/middlewares/arvados_api_token.rb |  7 ++----
 services/api/lib/simulate_job_log.rb              |  8 ++----
 services/api/script/cancel_stale_jobs.rb          |  8 +++---
 services/api/script/crunch-dispatch.rb            | 30 +++++++++++------------
 services/api/script/get_anonymous_user_token.rb   |  6 ++---
 services/api/test/unit/arvados_model_test.rb      |  4 +--
 6 files changed, 25 insertions(+), 38 deletions(-)

       via  b5c40a0304a9de42ae0ed3d0517e1365552c0e04 (commit)
      from  50e9e5553d2cc194698633753c302789ae5bb2fc (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit b5c40a0304a9de42ae0ed3d0517e1365552c0e04
Author: Radhika Chippada <radhika at curoverse.com>
Date:   Mon Mar 16 19:07:01 2015 -0400

    5383: revert back db_current_time update to Time.now in api scripts and middleware rb files.

diff --git a/services/api/app/middlewares/arvados_api_token.rb b/services/api/app/middlewares/arvados_api_token.rb
index 2bee50c..57d3ad0 100644
--- a/services/api/app/middlewares/arvados_api_token.rb
+++ b/services/api/app/middlewares/arvados_api_token.rb
@@ -2,10 +2,7 @@
 # this in the Rack stack instead of in ApplicationController because
 # websockets needs access to authentication but doesn't use any of the rails
 # active dispatch infrastructure.
-require 'db_current_time'
-
 class ArvadosApiToken
-  include DbCurrentTime
 
   # Create a new ArvadosApiToken handler
   # +app+  The next layer of the Rack stack.
@@ -27,7 +24,7 @@ class ArvadosApiToken
     params = request.params
     remote_ip = env["action_dispatch.remote_ip"]
 
-    Thread.current[:request_starttime] = db_current_time
+    Thread.current[:request_starttime] = Time.now
     user = nil
     api_client = nil
     api_client_auth = nil
@@ -54,7 +51,7 @@ class ArvadosApiToken
     Thread.current[:api_client] = api_client
     Thread.current[:user] = user
     if api_client_auth
-      api_client_auth.last_used_at = db_current_time
+      api_client_auth.last_used_at = Time.now
       api_client_auth.last_used_by_ip_address = remote_ip.to_s
       api_client_auth.save validate: false
     end
diff --git a/services/api/lib/simulate_job_log.rb b/services/api/lib/simulate_job_log.rb
index 65ab021..fc124c8 100644
--- a/services/api/lib/simulate_job_log.rb
+++ b/services/api/lib/simulate_job_log.rb
@@ -1,15 +1,11 @@
-require 'db_current_time'
-
 module SimulateJobLog
-  include DbCurrentTime
-
   def replay(filename, multiplier = 1, simulated_job_uuid = nil)
     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 = db_current_time
+    actual_start_time = Time.now
     log_start_time = nil
 
     act_as_system_user do
@@ -33,7 +29,7 @@ module SimulateJobLog
         # 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 = db_current_time - actual_start_time
+        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
diff --git a/services/api/script/cancel_stale_jobs.rb b/services/api/script/cancel_stale_jobs.rb
index e59e8d7..4949ec0 100755
--- a/services/api/script/cancel_stale_jobs.rb
+++ b/services/api/script/cancel_stale_jobs.rb
@@ -16,22 +16,20 @@ require File.dirname(__FILE__) + '/../config/environment'
 
 class CancelJobs
   include ApplicationHelper
-  include DbCurrentTime
 
   def cancel_stale_jobs
     act_as_system_user do
       Job.running.each do |jobrecord|
         f = Log.where("object_uuid=?", jobrecord.uuid).limit(1).order("created_at desc").first
         if f
-          current_time = db_current_time
-          age = (current_time - f.created_at)
+          age = (Time.now - f.created_at)
           if age > 300
             $stderr.puts "dispatch: failing orphan job #{jobrecord.uuid}, last log is #{age} seconds old"
             # job is marked running, but not known to crunch-dispatcher, and
             # hasn't produced any log entries for 5 minutes, so mark it as failed.
             jobrecord.running = false
-            jobrecord.cancelled_at ||= current_time
-            jobrecord.finished_at ||= current_time
+            jobrecord.cancelled_at ||= Time.now
+            jobrecord.finished_at ||= Time.now
             if jobrecord.success.nil?
               jobrecord.success = false
             end
diff --git a/services/api/script/crunch-dispatch.rb b/services/api/script/crunch-dispatch.rb
index 6faf931..ab4f70e 100755
--- a/services/api/script/crunch-dispatch.rb
+++ b/services/api/script/crunch-dispatch.rb
@@ -52,7 +52,6 @@ end
 
 class Dispatcher
   include ApplicationHelper
-  include DbCurrentTime
 
   def initialize
     @crunch_job_bin = (ENV['CRUNCH_JOB_BIN'] || `which arv-crunch-job`.strip)
@@ -217,7 +216,7 @@ class Dispatcher
     nodelist = nodes_available_for_job_now(job)
     if nodelist.nil? and not did_recently(:wait_for_available_nodes, 3600)
       $stderr.puts "dispatch: waiting for nodes for #{job.uuid}"
-      @node_wait_deadline = db_current_time + 5.minutes
+      @node_wait_deadline = Time.now + 5.minutes
     end
     nodelist
   end
@@ -261,7 +260,7 @@ class Dispatcher
       # We already made a token for this job, but we need a new one
       # because modified_by_user_uuid has changed (the job will run
       # as a different user).
-      @authorizations[job.uuid].update_attributes expires_at: db_current_time
+      @authorizations[job.uuid].update_attributes expires_at: Time.now
       @authorizations[job.uuid] = nil
     end
     if not @authorizations[job.uuid]
@@ -357,7 +356,7 @@ class Dispatcher
       when :slurm_immediate
         nodelist = nodes_available_for_job(job)
         if nodelist.nil?
-          if db_current_time < @node_wait_deadline
+          if Time.now < @node_wait_deadline
             break
           else
             next
@@ -427,7 +426,7 @@ class Dispatcher
         bytes_logged: 0,
         events_logged: 0,
         log_throttle_is_open: true,
-        log_throttle_reset_time: db_current_time + Rails.configuration.crunch_log_throttle_period,
+        log_throttle_reset_time: Time.now + Rails.configuration.crunch_log_throttle_period,
         log_throttle_bytes_so_far: 0,
         log_throttle_lines_so_far: 0,
         log_throttle_bytes_skipped: 0,
@@ -451,18 +450,18 @@ class Dispatcher
       if (running_job[:bytes_logged] >
           Rails.configuration.crunch_limit_log_bytes_per_job)
         message = "Exceeded log limit #{Rails.configuration.crunch_limit_log_bytes_per_job} bytes (crunch_limit_log_bytes_per_job). Log will be truncated."
-        running_job[:log_throttle_reset_time] = db_current_time + 100.years
+        running_job[:log_throttle_reset_time] = Time.now + 100.years
         running_job[:log_throttle_is_open] = false
 
       elsif (running_job[:log_throttle_bytes_so_far] >
              Rails.configuration.crunch_log_throttle_bytes)
-        remaining_time = running_job[:log_throttle_reset_time] - db_current_time
+        remaining_time = running_job[:log_throttle_reset_time] - Time.now
         message = "Exceeded rate #{Rails.configuration.crunch_log_throttle_bytes} bytes per #{Rails.configuration.crunch_log_throttle_period} seconds (crunch_log_throttle_bytes). Logging will be silenced for the next #{remaining_time.round} seconds.\n"
         running_job[:log_throttle_is_open] = false
 
       elsif (running_job[:log_throttle_lines_so_far] >
              Rails.configuration.crunch_log_throttle_lines)
-        remaining_time = running_job[:log_throttle_reset_time] - db_current_time
+        remaining_time = running_job[:log_throttle_reset_time] - Time.now
         message = "Exceeded rate #{Rails.configuration.crunch_log_throttle_lines} lines per #{Rails.configuration.crunch_log_throttle_period} seconds (crunch_log_throttle_lines), logging will be silenced for the next #{remaining_time.round} seconds.\n"
         running_job[:log_throttle_is_open] = false
       end
@@ -487,7 +486,7 @@ class Dispatcher
     @running.each do |job_uuid, j|
       job = j[:job]
 
-      now = db_current_time
+      now = Time.now
       if now > j[:log_throttle_reset_time]
         # It has been more than throttle_period seconds since the last
         # checkpoint so reset the throttle
@@ -664,7 +663,7 @@ class Dispatcher
     # Invalidate the per-job auth token, unless the job is still queued and we
     # might want to try it again.
     if jobrecord.state != "Queued"
-      j_done[:job_auth].update_attributes expires_at: db_current_time
+      j_done[:job_auth].update_attributes expires_at: Time.now
     end
 
     @running.delete job_done.uuid
@@ -681,7 +680,7 @@ class Dispatcher
     end
 
     expire_tokens.each do |k, v|
-      v.update_attributes expires_at: db_current_time
+      v.update_attributes expires_at: Time.now
       @pipe_auth_tokens.delete k
     end
   end
@@ -722,9 +721,8 @@ class Dispatcher
   protected
 
   def did_recently(thing, min_interval)
-    current_time = db_current_time
-    if !@did_recently[thing] or @did_recently[thing] < current_time - min_interval
-      @did_recently[thing] = current_time
+    if !@did_recently[thing] or @did_recently[thing] < Time.now - min_interval
+      @did_recently[thing] = Time.now
       false
     else
       true
@@ -739,7 +737,7 @@ class Dispatcher
     # it has been at least crunch_log_seconds_between_events seconds since
     # the last flush.
     if running_job[:stderr_buf_to_flush].size > Rails.configuration.crunch_log_bytes_per_event or
-        (db_current_time - running_job[:stderr_flushed_at]) >= Rails.configuration.crunch_log_seconds_between_events
+        (Time.now - running_job[:stderr_flushed_at]) >= Rails.configuration.crunch_log_seconds_between_events
       begin
         log = Log.new(object_uuid: running_job[:job].uuid,
                       event_type: 'stderr',
@@ -752,7 +750,7 @@ class Dispatcher
         $stderr.puts exception.backtrace
       end
       running_job[:stderr_buf_to_flush] = ''
-      running_job[:stderr_flushed_at] = db_current_time
+      running_job[:stderr_flushed_at] = Time.now
     end
   end
 end
diff --git a/services/api/script/get_anonymous_user_token.rb b/services/api/script/get_anonymous_user_token.rb
index 141f746..6964af0 100755
--- a/services/api/script/get_anonymous_user_token.rb
+++ b/services/api/script/get_anonymous_user_token.rb
@@ -21,15 +21,13 @@ get_existing = opts[:get]
 require File.dirname(__FILE__) + '/../config/environment'
 
 include ApplicationHelper
-include DbCurrentTime
-
 act_as_system_user
 
 def create_api_client_auth
   api_client_auth = ApiClientAuthorization.
     new(user: anonymous_user,
         api_client_id: 0,
-        expires_at: db_current_time + 100.years,
+        expires_at: Time.now + 100.years,
         scopes: ['GET /'])
   api_client_auth.save!
   api_client_auth.reload
@@ -38,7 +36,7 @@ end
 if get_existing
   api_client_auth = ApiClientAuthorization.
     where('user_id=?', anonymous_user.id.to_i).
-    where('expires_at>?', db_current_time).
+    where('expires_at>?', Time.now).
     select { |auth| auth.scopes == ['GET /'] }.
     first
 end
diff --git a/services/api/test/unit/arvados_model_test.rb b/services/api/test/unit/arvados_model_test.rb
index 44c8742..540ad0e 100644
--- a/services/api/test/unit/arvados_model_test.rb
+++ b/services/api/test/unit/arvados_model_test.rb
@@ -174,7 +174,7 @@ class ArvadosModelTest < ActiveSupport::TestCase
     assert group.valid?, "group is not valid"
 
     results = Group.where(created_at: group.created_at)
-    assert_equal true, results.any?, "Expected one or more groups when searched with created time"
-    assert_equal group.uuid, results.first.uuid, "Expected group uuid in results"
+    assert_equal true, results.map(&:uuid).include?(group.uuid),
+      "Expected new group uuid in results when searched with its created_at timestamp"
   end
 end

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list