-
Notifications
You must be signed in to change notification settings - Fork 107
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
refactor how jobs are logged in the project manager #3740
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
|
||
module JobLogger | ||
|
||
def upsert_job!(directory, job) | ||
existing_jobs = jobs(directory) | ||
stored_job = existing_jobs.detect { |j| j.id == job.id && j.cluster == job.cluster } | ||
|
||
if stored_job.nil? | ||
new_jobs = (existing_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 | ||
|
||
JobLoggerHelper.write_log(directory, new_jobs) | ||
end | ||
|
||
# def write_job_log!(directory, jobs) | ||
# JobLoggerHelper.write_log!(directory, jobs) | ||
# endd | ||
|
||
def jobs(directory) | ||
file = JobLoggerHelper.log_file(directory) | ||
begin | ||
data = YAML.safe_load(File.read(file.to_s), permitted_classes: [Time]).to_a | ||
data.map { |job_data| HpcJob.new(**job_data) } | ||
rescue StandardError => e | ||
Rails.logger.error("Cannot read job log file '#{file}' due to error: #{e}") | ||
[] | ||
end | ||
end | ||
|
||
# helper methods here are located here so that they don't | ||
# bleed into the class that uses this module | ||
class JobLoggerHelper | ||
class << self | ||
def log_file(directory) | ||
Pathname.new("#{directory}/.ondemand/job_log.yml").tap do |path| | ||
FileUtils.touch(path.to_s) unless path.exist? | ||
end | ||
end | ||
|
||
def write_log(directory, jobs) | ||
file = log_file(directory) | ||
File.write(file.to_s, jobs.to_yaml) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like completed jobs are not being saved with clusters, which is causing there to be duplicate entries in the job log that appear to never load in the projects#show page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for checking! I thought there was something buggy here but couldn't quite put my finger on it.