25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'app/models/logical/naf/construction_zone/foreman.rb', line 25
def limited_by_run_group?(application_run_group_restriction, application_run_group_name, application_run_group_limit, affinities)
if (application_run_group_restriction.id == ::Naf::ApplicationRunGroupRestriction.no_limit.id ||
application_run_group_limit.nil? ||
application_run_group_name.nil?)
false
elsif application_run_group_restriction.id == ::Naf::ApplicationRunGroupRestriction.limited_per_machine.id
machine_affinity = nil
affinities.each do |affinity|
machine_affinity = ::Naf::Affinity.find_by_id(affinity[:affinity_id])
if machine_affinity.present? && machine_affinity.affinity_classification_name == 'machine'
break
end
end
if machine_affinity.present?
queued_jobs = ::Naf::QueuedJob.
joins(:historical_job).
joins("INNER JOIN #{Naf.schema_name}.historical_job_affinity_tabs AS hjat
ON hjat.historical_job_id = #{Naf.schema_name}.historical_jobs.id").
where("#{Naf.schema_name}.historical_jobs.application_run_group_name = ? AND hjat.affinity_id = ?",
application_run_group_name, machine_affinity.id).count
running_jobs = ::Naf::RunningJob.where(
application_run_group_name: application_run_group_name,
started_on_machine_id: machine_affinity.affinity_name
).count
queued_jobs + running_jobs >= application_run_group_limit
else
logger.warn "application schedule does not have affinity associated with a machine"
false
end
elsif application_run_group_restriction.id == ::Naf::ApplicationRunGroupRestriction.limited_per_all_machines.id
(::Naf::QueuedJob.where(application_run_group_name: application_run_group_name).count +
::Naf::RunningJob.where(application_run_group_name: application_run_group_name).count) >= application_run_group_limit
else
logger.warn "not limited by run group restriction but don't know why: #{application_run_group_restriction.inspect}"
true
end
end
|