[ARVADOS] created: 680bc629dc473d877218b1ed9351fac4020d4657

Git user git at public.curoverse.com
Mon Dec 19 15:29:57 EST 2016


        at  680bc629dc473d877218b1ed9351fac4020d4657 (commit)


commit 680bc629dc473d877218b1ed9351fac4020d4657
Author: Lucas Di Pentima <lucas at curoverse.com>
Date:   Mon Dec 19 17:26:38 2016 -0300

    10671: Set up values for pipeline instance started_at and finished_at attributes on state changes.
    Updated tests accordingly.

diff --git a/services/api/app/models/pipeline_instance.rb b/services/api/app/models/pipeline_instance.rb
index 77a0736..dada5d6 100644
--- a/services/api/app/models/pipeline_instance.rb
+++ b/services/api/app/models/pipeline_instance.rb
@@ -12,6 +12,7 @@ class PipelineInstance < ArvadosModel
   before_validation :verify_status
   before_create :set_state_before_save
   before_save :set_state_before_save
+  before_save :update_timestamps_when_state_changes
 
   api_accessible :user, extend: :common do |t|
     t.add :pipeline_template_uuid
@@ -136,4 +137,15 @@ class PipelineInstance < ArvadosModel
     end
   end
 
+  def update_timestamps_when_state_changes
+    return if not (state_changed? or new_record?)
+
+    case state
+    when RunningOnServer, RunningOnClient
+      self.started_at ||= db_current_time
+    when Failed, Complete
+      self.finished_at ||= db_current_time
+    end
+  end
+
 end
diff --git a/services/api/test/unit/pipeline_instance_test.rb b/services/api/test/unit/pipeline_instance_test.rb
index fc40d06..05ba135 100644
--- a/services/api/test/unit/pipeline_instance_test.rb
+++ b/services/api/test/unit/pipeline_instance_test.rb
@@ -38,6 +38,8 @@ class PipelineInstanceTest < ActiveSupport::TestCase
     pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
     assert_equal PipelineInstance::New, pi.state, 'expected state to be New after adding component with input'
     assert_equal pi.components.size, 1, 'expected one component'
+    assert_nil pi.started_at, 'expected started_at to be nil on new pipeline instance'
+    assert_nil pi.finished_at, 'expected finished_at to be nil on new pipeline instance'
 
     # add a component with no input not required
     component = {'script_parameters' => {"input_not_provided" => {"required" => false}}}
@@ -61,6 +63,8 @@ class PipelineInstanceTest < ActiveSupport::TestCase
     pi.save
     pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
     assert_equal PipelineInstance::RunningOnServer, pi.state, 'expected state to be RunningOnServer after updating state to RunningOnServer'
+    assert_not_nil pi.started_at, 'expected started_at to have a value on a running pipeline instance'
+    assert_nil pi.finished_at, 'expected finished_at to be nil on a running pipeline instance'
 
     pi.state = PipelineInstance::Paused
     pi.save
@@ -71,6 +75,8 @@ class PipelineInstanceTest < ActiveSupport::TestCase
     pi.save
     pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
     assert_equal PipelineInstance::Complete, pi.state, 'expected state to be Complete after updating state to Complete'
+    assert_not_nil pi.started_at, 'expected started_at to have a value on a completed pipeline instance'
+    assert_not_nil pi.finished_at, 'expected finished_at to have a value on a completed pipeline instance'
 
     pi.state = 'bogus'
     pi.save
@@ -81,6 +87,8 @@ class PipelineInstanceTest < ActiveSupport::TestCase
     pi.save
     pi = PipelineInstance.find_by_uuid 'zzzzz-d1hrv-f4gneyn6br1xize'
     assert_equal PipelineInstance::Failed, pi.state, 'expected state to be Failed after updating state to Failed'
+    assert_not_nil pi.started_at, 'expected started_at to have a value on a failed pipeline instance'
+    assert_not_nil pi.finished_at, 'expected finished_at to have a value on a failed pipeline instance'
   end
 
   test "update attributes for pipeline with two components" do

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


hooks/post-receive
-- 




More information about the arvados-commits mailing list