Class: Naf::QueuedJob
Class Method Summary collapse
- .check_weight_sum(affinity_id, running_job_weight_count, machine_weight_count) ⇒ Object
- .exclude_run_group_names(names) ⇒ Object
- .is_not_restricted_by_run_group(machine) ⇒ Object
-
.order_by_priority ⇒ Object
————————- *** Class Methods *** +++++++++++++++++++++++++.
- .prerequisites_finished ⇒ Object
- .runnable_by_machine(machine) ⇒ Object
- .weight_available_on_machine(machine) ⇒ Object
Methods inherited from NafBase
Class Method Details
.check_weight_sum(affinity_id, running_job_weight_count, machine_weight_count) ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'app/models/naf/queued_job.rb', line 136 def self.check_weight_sum(affinity_id, running_job_weight_count, machine_weight_count) where(" id IN ( SELECT historical_job_id FROM #{::Naf.schema_name}.historical_job_affinity_tabs AS t WHERE EXISTS ( SELECT 1 FROM #{::Naf.schema_name}.queued_jobs AS j WHERE t.historical_job_id = j.id ) AND EXISTS ( SELECT 1 FROM #{::Naf.schema_name}.affinities AS a WHERE a.id = '#{affinity_id}' AND t.affinity_id = a.id ) AND COALESCE(affinity_parameter, 0) + #{running_job_weight_count} > #{machine_weight_count} ) ") end |
.exclude_run_group_names(names) ⇒ Object
44 45 46 47 48 49 50 |
# File 'app/models/naf/queued_job.rb', line 44 def self.exclude_run_group_names(names) if names.present? where("application_run_group_name NOT IN (?)", names) else where({}) end end |
.is_not_restricted_by_run_group(machine) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'app/models/naf/queued_job.rb', line 52 def self.is_not_restricted_by_run_group(machine) sql = <<-SQL ( #{Naf.schema_name}.queued_jobs.application_run_group_name is null OR #{Naf.schema_name}.queued_jobs.application_run_group_limit is null OR #{Naf.schema_name}.application_run_group_restrictions.application_run_group_restriction_name = 'no limit' OR ( #{Naf.schema_name}.application_run_group_restrictions.application_run_group_restriction_name = 'limited per machine' AND (select count(*) < #{Naf.schema_name}.queued_jobs.application_run_group_limit from #{Naf.schema_name}.running_jobs as rj where rj.application_run_group_name = #{Naf.schema_name}.queued_jobs.application_run_group_name and rj.started_on_machine_id = #{machine.id}) ) OR ( application_run_group_restrictions.application_run_group_restriction_name = 'limited per all machines' AND (select count(*) < #{Naf.schema_name}.queued_jobs.application_run_group_limit from #{Naf.schema_name}.running_jobs as rj where rj.application_run_group_name = #{Naf.schema_name}.queued_jobs.application_run_group_name) ) ) SQL return joins(:application_run_group_restriction). where(sql) end |
.order_by_priority ⇒ Object
*** Class Methods *** +++++++++++++++++++++++++
40 41 42 |
# File 'app/models/naf/queued_job.rb', line 40 def self.order_by_priority order("priority, created_at") end |
.prerequisites_finished ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'app/models/naf/queued_job.rb', line 99 def self.prerequisites_finished where("NOT EXISTS ( SELECT 1 FROM #{::Naf.schema_name}.historical_job_prerequisites AS p WHERE p.historical_job_id = #{::Naf.schema_name}.queued_jobs.id AND EXISTS ( SELECT 1 FROM #{::Naf.schema_name}.historical_jobs AS j WHERE p.prerequisite_historical_job_id = j.id AND j.finished_at IS NULL ) )" ) end |
.runnable_by_machine(machine) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'app/models/naf/queued_job.rb', line 84 def self.runnable_by_machine(machine) where("NOT EXISTS ( SELECT 1 FROM #{::Naf.schema_name}.historical_job_affinity_tabs AS t WHERE t.historical_job_id = #{::Naf.schema_name}.queued_jobs.id AND NOT EXISTS ( SELECT 1 FROM #{::Naf.schema_name}.machine_affinity_slots AS s WHERE s.affinity_id = t.affinity_id AND s.machine_id = #{machine.id} ) )" ) end |
.weight_available_on_machine(machine) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'app/models/naf/queued_job.rb', line 114 def self.weight_available_on_machine(machine) machine_parameter_weights = {} machine.machine_affinity_slots.each do |slot| machine_parameter_weights[slot.affinity_id] = slot.affinity_parameter.to_f end running_job_weights = ::Naf::RunningJob.affinity_weights(machine) queued_jobs = [] machine_parameter_weights.each do |affinity_id, parameter_weight| queued_jobs |= ::Naf::QueuedJob. check_weight_sum(affinity_id, running_job_weights[affinity_id], parameter_weight). map(&:id) end if queued_jobs.empty? where({}) else where("#{::Naf.schema_name}.queued_jobs.id NOT IN (?)", queued_jobs) end end |