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

PM job state management #3702

Merged
merged 3 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 3 additions & 2 deletions apps/dashboard/app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,13 @@ def destroy

# GET /projects/:project_id/jobs/:cluster/:jobid
def job_details
project = Project.find(params[:project_id])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should avoid using params directly and instead us maybe job_details_params so the list of parameters we're accessing are known to be valid and permitted.

cluster_str = job_details_params[:cluster].to_s
cluster = OodAppkit.clusters[cluster_str.to_sym]
render(:status => 404) if cluster.nil?

job_info = cluster.job_adapter.info(job_details_params[:jobid].to_s)
hpc_job = HpcJob.from_core_info(info: job_info, cluster: cluster_str)
hpc_job = project.job_from_id(job_details_params[:jobid].to_s, cluster_str)

render(partial: 'job_details', locals: { job: hpc_job })
end

Expand Down
23 changes: 22 additions & 1 deletion apps/dashboard/app/models/launcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,15 @@ def jobs
end
end

# When a job is requested, update before returning
def job_from_id(job_id, cluster)
job = stored_job_from_id(job_id, cluster)
unless job.nil? || job.status.to_s == 'completed'
update_job_log(job_id, cluster)
end
stored_job_from_id(job_id, cluster)
end

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

Expand Down Expand Up @@ -307,11 +316,23 @@ def most_recent_job
end.reverse.first.to_h
end

def stored_job_from_id(job_id, cluster)
jobs.detect { |j| j.id == job_id && j.cluster == cluster }
end

def update_job_log(job_id, cluster)
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]).map(&:to_h)
existing_jobs = jobs
stored_job = stored_job_from_id(job_id, cluster)
if stored_job.nil?
new_jobs = (jobs + [job.to_h]).map(&:to_h)
else
new_jobs = existing_jobs.map(&:to_h)
idx = existing_jobs.index(stored_job)
new_jobs[idx].merge!(job.to_h) { |key, old_val, new_val| new_val.nil? ? old_val : new_val }
end

File.write(job_log_file.to_s, new_jobs.to_yaml)
end
Expand Down
8 changes: 8 additions & 0 deletions apps/dashboard/app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,14 @@ def jobs
end.flatten
end

def job_from_id(job_id, cluster)
launchers = Launcher.all(directory)
launchers.each do |launcher|
job = launcher.job_from_id(job_id, cluster)
return job unless job.nil?
end
end
Comment on lines +206 to +212
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's something wrong here that I think I started. jobs are associated with the launchers and that's why you have to do all this weirdness here. But I think a better/simpler paradigm really is that the project itself keeps the job log and the entries have a relationship to the launcher (if we even need such a relationship).

Which is really just to say that I think we should rethink & refactor this whole paradigm before it gets worse. I think we can move forward with this as it is, but will likely have to change it almost immediately.


def readme_path
file = Dir.glob("#{directory}/README.{md,txt}").first.to_s
File.readable?(file) ? file : nil
Expand Down
Loading