From 5a3082ad66b233f618edddb08b20accb11bf97b3 Mon Sep 17 00:00:00 2001 From: codecat555 Date: Mon, 18 Mar 2024 12:39:34 -0700 Subject: [PATCH] Add completed_at attribute to mark job finish. (#3424) --- apps/dashboard/app/models/batch_connect/session.rb | 7 ++++++- apps/dashboard/test/models/batch_connect/session_test.rb | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/apps/dashboard/app/models/batch_connect/session.rb b/apps/dashboard/app/models/batch_connect/session.rb index 99f18f3cfd..311e7eae7a 100644 --- a/apps/dashboard/app/models/batch_connect/session.rb +++ b/apps/dashboard/app/models/batch_connect/session.rb @@ -31,6 +31,10 @@ def get_binding # @return [Integer] created at attr_accessor :created_at + # When this session finished, as a unix timestamp + # @return [Integer] completed at + attr_accessor :completed_at + # Token describing app and sub app # @return [String] app token attr_accessor :token @@ -87,7 +91,7 @@ def app # Attributes used for serialization # @return [Hash] attributes to be serialized def attributes - %w(id cluster_id job_id created_at token title script_type cache_completed).map do |attribute| + %w(id cluster_id job_id created_at token title script_type cache_completed completed_at).map do |attribute| [ attribute, nil ] end.to_h end @@ -421,6 +425,7 @@ def update_info def update_cache_completed! if (! cache_completed) && completed? self.cache_completed = true + self.completed_at = Time.now.to_i db_file.write(to_json) end end diff --git a/apps/dashboard/test/models/batch_connect/session_test.rb b/apps/dashboard/test/models/batch_connect/session_test.rb index c7c830bcf4..48446d44a9 100644 --- a/apps/dashboard/test/models/batch_connect/session_test.rb +++ b/apps/dashboard/test/models/batch_connect/session_test.rb @@ -551,7 +551,8 @@ def completed? 'token' => 'bc_jupyter', 'title' => 'Jupyter Notebook', 'script_type' => 'basic', - 'cache_completed' => nil + 'cache_completed' => nil, + 'completed_at' => nil } Timecop.freeze(now) do assert session.save(app: bc_jupyter_app, context: ctx), session.errors.each(&:to_s).to_s