-
Notifications
You must be signed in to change notification settings - Fork 17
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
[PART 1] Create a "priority only" distribution #14691
Changes from 19 commits
3222a99
22a4912
a45df4b
1cee714
2fdbc09
b653340
25c9606
3bd0698
fb7e038
df2fd01
0932ca5
904c52f
a0a26e5
98c954f
12013e3
49db6c4
3d8b6b2
b902ddc
4c47117
b75e3a9
04535b7
0b8f944
ef4f5ba
4e05c00
5d96969
ed9081d
ca76476
046454e
10b1656
edb04dd
d562a24
78e9e7a
463d33c
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 |
---|---|---|
|
@@ -9,8 +9,8 @@ class Distribution < CaseflowRecord | |
|
||
validates :judge, presence: true | ||
validate :validate_user_is_judge, on: :create | ||
validate :validate_number_of_unassigned_cases, on: :create | ||
validate :validate_days_waiting_of_unassigned_cases, on: :create | ||
validate :validate_number_of_unassigned_cases, on: :create, unless: :priority_push? | ||
validate :validate_days_waiting_of_unassigned_cases, on: :create, unless: :priority_push? | ||
validate :validate_judge_has_no_pending_distributions, on: :create | ||
|
||
enum status: { pending: "pending", started: "started", error: "error", completed: "completed" } | ||
|
@@ -20,13 +20,15 @@ class Distribution < CaseflowRecord | |
CASES_PER_ATTORNEY = 3 | ||
ALTERNATIVE_BATCH_SIZE = 15 | ||
|
||
scope :priority_push, -> { where(priority_push: true) } | ||
|
||
class << self | ||
def pending_for_judge(judge) | ||
find_by(status: %w[pending started], judge: judge) | ||
where(status: %w[pending started], judge: judge) | ||
end | ||
end | ||
|
||
def distribute! | ||
def distribute!(limit = nil) | ||
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. Allows us to stipulate a limit for priority push cases, when we get to the "aim to hit priority target" portion of the job |
||
return unless %w[pending error].include? status | ||
|
||
if status == "error" | ||
|
@@ -41,7 +43,7 @@ def distribute! | |
multi_transaction do | ||
ActiveRecord::Base.connection.execute "SET LOCAL statement_timeout = #{transaction_time_out}" | ||
|
||
ama_distribution | ||
priority_push? ? priority_push_distribution(limit) : ama_distribution | ||
|
||
update!(status: "completed", completed_at: Time.zone.now, statistics: ama_statistics) | ||
end | ||
|
@@ -74,7 +76,9 @@ def validate_days_waiting_of_unassigned_cases | |
end | ||
|
||
def validate_judge_has_no_pending_distributions | ||
errors.add(:judge, :pending_distribution) if self.class.pending_for_judge(judge) | ||
if self.class.pending_for_judge(judge).where(priority_push: priority_push).exists? | ||
errors.add(:judge, :pending_distribution) | ||
end | ||
end | ||
|
||
def judge_tasks | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,14 @@ def distribute_appeals(distribution, priority: false, genpop: "any", limit: 1) | |
base_relation: base_relation, genpop: genpop, judge: distribution.judge | ||
).call | ||
|
||
# genpop 'any' returns 2 arrays of the limited base relation. This means if we only request 2 cases, appeals is a | ||
# 2x2 array containing 4 cases overall and we will end up distributing 4 cases rather than 2. Instead, reinstate the | ||
# limit here by filtering out the newest cases | ||
if genpop == "any" | ||
appeals_to_reject = appeals.flatten.sort_by(&:ready_for_distribution_at).drop(limit) | ||
appeals = [appeals.first - appeals_to_reject, appeals.last - appeals_to_reject] | ||
end | ||
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. Found a bug! Detailed here |
||
|
||
HearingRequestCaseDistributor.new( | ||
appeals: appeals, genpop: genpop, distribution: distribution, priority: priority | ||
).call | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,7 +118,7 @@ class DocketNumberCentennialLoop < StandardError; end | |
#{JOIN_ASSOCIATED_VLJS_BY_PRIOR_DECISIONS} | ||
) | ||
where ((VLJ = ? and 1 = ?) or (VLJ is null and 1 = ?)) | ||
and rownum <= ? | ||
and (rownum <= ? or 1 = ?) | ||
" | ||
|
||
SELECT_NONPRIORITY_APPEALS = " | ||
|
@@ -324,7 +324,8 @@ def self.distribute_priority_appeals(judge, genpop, limit, dry_run = false) | |
judge.vacols_attorney_id, | ||
(genpop == "any" || genpop == "not_genpop") ? 1 : 0, | ||
(genpop == "any" || genpop == "only_genpop") ? 1 : 0, | ||
limit | ||
limit, | ||
limit.nil? ? 1 : 0 | ||
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. Allows nil limit to be passed to distribute_priority_appeals, indicating that any and all cases should be distributed |
||
]) | ||
|
||
distribute_appeals(fmtd_query, judge, dry_run) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class AddPriorityToDistributions < ActiveRecord::Migration[5.2] | ||
def up | ||
add_column :distributions, :priority_push, :boolean, comment: "Whether or not this distribution is a priority-appeals-only push to judges via a weekly job (not manually requested)" | ||
change_column_default :distributions, :priority_push, false | ||
end | ||
|
||
def down | ||
remove_column :distributions, :priority_push | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
class BackfillDistributionPriority < ActiveRecord::Migration[5.2] | ||
disable_ddl_transaction! | ||
|
||
def change | ||
Distribution.unscoped.in_batches do |relation| | ||
relation.update_all priority_push: false | ||
sleep(0.1) | ||
end | ||
end | ||
end |
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.
priority push does not work off of batch size, it either distributes without limit or distributes the provided limit.