-
Notifications
You must be signed in to change notification settings - Fork 0
AP-468 add priority job feature #3
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,13 +31,13 @@ def eligible_job? | |
|
|
||
| # Extract the data from the raw jobs into the fields we need | ||
| # config/ucpath_fields.yml contains the fields/jpath we want to extract | ||
| def find_eligible_job(raw_jobs) | ||
| raw_jobs.first.each do |job_hash| | ||
| job = OpenStruct.new( | ||
| Config.ucpath_job_fields.to_h do |field| | ||
| [field['name'], JsonPath.on(job_hash, field['jpath']).first || ''] | ||
| end | ||
| ) | ||
| def find_eligible_job(job_list) | ||
| priority_job_hash = find_priority_jobs(job_list) | ||
|
|
||
| return map_job_to_struct(priority_job_hash) if priority_job_hash | ||
|
|
||
| job_list.first.each do |job_hash| | ||
| job = map_job_to_struct(job_hash) | ||
|
|
||
| # First one - save it incase we don't find any eligible jobs! | ||
| @first_job ||= job | ||
|
|
@@ -73,6 +73,23 @@ def check_if_eligible(j) | |
| end | ||
| # rubocop :enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity | ||
|
|
||
| def find_priority_jobs(job_list) | ||
| job_list.flatten.find do |jh| | ||
| job_code = jh.dig('position', 'jobCode', 'code', 'code') | ||
| status = jh.dig('position', 'active', 'code') | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe, i'm not reading this right but should it be
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You'd think... but nope, here's the JSON from the API:
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i'm a little confused by this too - i din't think it's parsing that file, but i see a similar json path in that file. how are these two things related?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maria is correct, it's not parsing ucpath_fields.yml. The new function (find_priority_jobs) is going through the JSON that is returned from the UCPath/Jobs API (looking for any job that is active and in the priority list). The JSONPath (from ucpath_fields.yml) is used to map data fields from the job hash (from the API) into an OpenStruct which gets passed back to the user object for further processing. |
||
|
|
||
| Config.check_ucpath_code('Priority Job Codes', job_code) && status == 'A' | ||
| end | ||
| end | ||
|
|
||
| def map_job_to_struct(job_hash) | ||
| OpenStruct.new( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OpenStruct is deprecated and will be removed from Ruby 3.5
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. UGH...yeah. I'll open a ticket to eventually move from openstructs to structs.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note - opened AP-584 for that work. |
||
| Config.ucpath_job_fields.to_h do |field| | ||
| [field['name'], JsonPath.on(job_hash, field['jpath']).first || ''] | ||
| end | ||
| ) | ||
| end | ||
|
|
||
| def fetch_jobs(id) | ||
| logger.info "#{id} - Fetching ucpath jobs data" | ||
| User.fetch_ucpath_jobs(id) | ||
|
|
||
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.
i know we had this before, but i'm a little concerned about YAML keys containing spaces - could we rename this something like
priority_job_codesor something similar? (i know we need to make similar changes throughout this file and in the code, too.)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.
Sure - that's definitely doable!