Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhance the projects#show page with list of active jobs #3473

Merged
merged 1 commit into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions apps/dashboard/app/assets/stylesheets/projects.scss
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,15 @@
.job-info .job-info-description{
display: block;
}

.list-toggler[aria-expanded="false"] span::after {
content: "▲";
font-size: 1.4em;
float: right;
}

.list-toggler[aria-expanded="true"] span::after {
content: "▼";
font-size: 1.4em;
float: right;
}
4 changes: 2 additions & 2 deletions apps/dashboard/app/javascript/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function pollForJobInfo(element) {
element.innerHTML = jobInfoDiv(jobId, state);
if(state !== 'completed') {
// keep going
setTimeout(pollForJobInfo, 10000, element);
setTimeout(pollForJobInfo, 30000, element);
}
})
.catch((error) => {
Expand All @@ -49,7 +49,7 @@ function pollForJobInfo(element) {
}

function jobInfoDiv(jobId, state, stateTitle='', stateDescription='') {
return `<div class="job-info">
return `<div class="job-info justify-content-center d-grid">
<span class="mr-2">${jobId}</span>
<span class="job-info-title badge ${cssBadgeForState(state)}" title="${stateTitle}">${state.toUpperCase()}</span>
<span class="job-info-description text-muted">${stateDescription}</span>
Expand Down
30 changes: 23 additions & 7 deletions apps/dashboard/app/models/launcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,26 @@ def most_recent_job_cluster
most_recent_job['cluster']
end

def active_jobs
@active_jobs ||= jobs.map do |job|
adapter = adapter(job['cluster'].to_sym).job_adapter
adapter.info(job['id'])
end.reject do |job|
job.status == :completed
end
end

def job_cluster(id)
job = jobs.select { |job| job['id'] == id }.first
return nil if job.nil?

job['cluster']
end

def jobs
@jobs ||= YAML.safe_load(File.read(job_log_file.to_s)).to_a
end

def create_default_script
return false if Launcher.scripts?(project_dir) || default_script_path.exist?

Expand Down Expand Up @@ -295,23 +315,19 @@ def cached_values
end

def most_recent_job
job_data.sort_by do |data|
jobs.sort_by do |data|
data['submit_time']
end.reverse.first.to_h
end

def update_job_log(job_id, cluster)
new_job_data = job_data + [{
new_jobs = jobs + [{
'id' => job_id,
'submit_time' => Time.now.to_i,
'cluster' => cluster.to_s
}]

File.write(job_log_file.to_s, new_job_data.to_yaml)
end

def job_data
@job_data ||= YAML.safe_load(File.read(job_log_file.to_s)).to_a
File.write(job_log_file.to_s, new_jobs.to_yaml)
end

def job_log_file
Expand Down
26 changes: 24 additions & 2 deletions apps/dashboard/app/views/projects/_launcher_details.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
disabled_class = disabled ? 'disabled' : ''
edit_title = "#{t('dashboard.edit')} launcher #{launcher.title}"
delete_title = "#{t('dashboard.delete')} launcher #{launcher.title}"
active_job_list_id = "active_job_list_#{launcher.id}"
active_job_list_button_id = "active_job_button_#{launcher.id}"
-%>

<div class='card'>
Expand Down Expand Up @@ -62,8 +64,28 @@
</div>
</div>

<div class="row">
<%= launcher.most_recent_job_id %>
<div class="row mt-2">
<div class="col-4">
<div class="list-group">
<a id="<%= active_job_list_button_id %>" class="btn btn-success list-toggler"
data-toggle="collapse" data-target="#<%= active_job_list_id %>"
aria-expanded="true" aria-controls="<%= active_job_list_id %>">
<span>Active Jobs</span>
</a>

<div id="<%= active_job_list_id %>" >
<%- launcher.active_jobs.each do |job| -%>
<a class="list-group-item list-group-item list-group-item-action justify-content-center"
data-job-poller="true"
data-job-cluster="<%= launcher.job_cluster(job.id) %>"
data-job-id="<%= job.id %>"
>
<%= job.id %>
</a>
<%- end -%>
</div>
</div>
</div>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/app/views/projects/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
</div>

<div class="row mb-3">
<div class="col-4">
<div class="col-2">
<div class="list-group" id="launcher_list" role="tablist">

<%- @scripts.each_with_index do |script, index| -%>
Expand Down
Loading