Skip to content

Commit

Permalink
serialize more job info
Browse files Browse the repository at this point in the history
  • Loading branch information
johrstrom committed Mar 29, 2024
1 parent e8ac6f4 commit 1d308ec
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 14 deletions.
32 changes: 32 additions & 0 deletions apps/dashboard/app/models/hpc_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# frozen_string_literal: true

class HpcJob < OodCore::Job::Info
attr_reader :cluster

COMPLETED = 'completed'

class << self
def from_core_info(info: nil, cluster: nil)
new(cluster: cluster, **info.to_h)
end
end

def initialize(cluster: nil, **args)
@cluster = cluster
super(**args)
end

def completed?
status.to_s == COMPLETED
end

def to_h
super.to_h.merge({ cluster: cluster,
status: status.to_s,
allocated_nodes: [] }).deep_stringify_keys
end

def cache_key
"#{cluster}_#{id}"
end
end
11 changes: 5 additions & 6 deletions apps/dashboard/app/models/launcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def job_cluster(id)
end

def jobs
@jobs ||= YAML.safe_load(File.read(job_log_file.to_s)).to_a
@jobs ||= YAML.safe_load(File.read(job_log_file.to_s), permitted_classes: [Time]).to_a
end

def create_default_script
Expand Down Expand Up @@ -321,11 +321,10 @@ def most_recent_job
end

def update_job_log(job_id, cluster)
new_jobs = jobs + [{
'id' => job_id,
'submit_time' => Time.now.to_i,
'cluster' => cluster.to_s
}]
adapter = adapter(cluster).job_adapter
info = adapter.info(job_id)
job = HpcJob.from_core_info(info: info, cluster: cluster)
new_jobs = jobs + [job.to_h]

File.write(job_log_file.to_s, new_jobs.to_yaml)
end
Expand Down
16 changes: 8 additions & 8 deletions apps/dashboard/test/system/project_manager_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,10 @@ def add_auto_environment_variable(project_id, script_id, save: true)

click_on 'Launch'
assert_selector('.alert-success', text: 'job-id-123')
assert_equal [{ 'id' => 'job-id-123',
'submit_time' => @expected_now,
'cluster' => 'owens' }],
YAML.safe_load(File.read("#{script_dir}/job_history.log"))
jobs = YAML.safe_load(File.read("#{script_dir}/job_history.log"), permitted_classes: [Time])

assert_equal(1, jobs.size)
assert_equal('job-id-123', jobs[0]['id'])
end
end

Expand Down Expand Up @@ -392,10 +392,10 @@ def add_auto_environment_variable(project_id, script_id, save: true)

click_on 'Launch'
assert_selector('.alert-success', text: 'job-id-123')
assert_equal [{ 'id' => 'job-id-123',
'submit_time' => @expected_now,
'cluster' => 'owens' }],
YAML.safe_load(File.read("#{script_dir}/job_history.log"))
jobs = YAML.safe_load(File.read("#{script_dir}/job_history.log"), permitted_classes: [Time])

assert_equal(1, jobs.size)
assert_equal('job-id-123', jobs[0]['id'])
end
end

Expand Down

0 comments on commit 1d308ec

Please sign in to comment.