@@ -31,13 +31,13 @@ def eligible_job?
3131
3232 # Extract the data from the raw jobs into the fields we need
3333 # config/ucpath_fields.yml contains the fields/jpath we want to extract
34- def find_eligible_job ( raw_jobs )
35- raw_jobs . first . each do | job_hash |
36- job = OpenStruct . new (
37- Config . ucpath_job_fields . to_h do | field |
38- [ field [ 'name' ] , JsonPath . on ( job_hash , field [ 'jpath' ] ) . first || '' ]
39- end
40- )
34+ def find_eligible_job ( job_list )
35+ priority_job_hash = find_priority_jobs ( job_list )
36+
37+ return map_job_to_struct ( priority_job_hash ) if priority_job_hash
38+
39+ job_list . first . each do | job_hash |
40+ job = map_job_to_struct ( job_hash )
4141
4242 # First one - save it incase we don't find any eligible jobs!
4343 @first_job ||= job
@@ -73,6 +73,23 @@ def check_if_eligible(j)
7373 end
7474 # rubocop :enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
7575
76+ def find_priority_jobs ( job_list )
77+ job_list . flatten . find do |jh |
78+ job_code = jh . dig ( 'position' , 'jobCode' , 'code' , 'code' )
79+ status = jh . dig ( 'position' , 'active' , 'code' )
80+
81+ Config . check_ucpath_code ( 'Priority Job Codes' , job_code ) && status == 'A'
82+ end
83+ end
84+
85+ def map_job_to_struct ( job_hash )
86+ OpenStruct . new (
87+ Config . ucpath_job_fields . to_h do |field |
88+ [ field [ 'name' ] , JsonPath . on ( job_hash , field [ 'jpath' ] ) . first || '' ]
89+ end
90+ )
91+ end
92+
7693 def fetch_jobs ( id )
7794 logger . info "#{ id } - Fetching ucpath jobs data"
7895 User . fetch_ucpath_jobs ( id )
0 commit comments