-
Notifications
You must be signed in to change notification settings - Fork 19
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
WIP Add auto-distributor logging #14897
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 |
---|---|---|
|
@@ -11,16 +11,24 @@ class RoundRobinTaskDistributor | |
def initialize(assignee_pool:, task_class:) | ||
@assignee_pool = assignee_pool.select(&:active?) | ||
@task_class = task_class | ||
@state = { | ||
class: self.class.name, | ||
invoker: "round_robin", | ||
task_class: @task_class&.name, | ||
assignee_pool: @assignee_pool.pluck(:id) | ||
} | ||
end | ||
|
||
def latest_task | ||
# Use id as a proxy for created_at since the id field is already indexed. | ||
# Request .visible_in_queue_table_view to avoid TimedHoldTask or similar tasks | ||
task_class | ||
latest = task_class | ||
.visible_in_queue_table_view | ||
.where(assigned_to: assignee_pool) | ||
.order(id: :desc) | ||
.first | ||
@state[:latest_task_id] = latest&.id | ||
latest | ||
end | ||
|
||
def last_assignee | ||
|
@@ -34,16 +42,22 @@ def last_assignee_index | |
def next_assignee_index | ||
return 0 unless last_assignee | ||
return 0 unless last_assignee_index | ||
curr_last_assignee = last_assignee | ||
@state[:last_assignee_id] = curr_last_assignee&.id | ||
|
||
(last_assignee_index + 1) % assignee_pool.length | ||
end | ||
|
||
def next_assignee(_options = {}) | ||
def next_assignee(options = {}) | ||
unless valid? | ||
fail Caseflow::Error::RoundRobinTaskDistributorError, message: errors.full_messages.join(", ") | ||
end | ||
|
||
assignee_pool[next_assignee_index] | ||
next_index = next_assignee_index | ||
@state[:next_index] = next_index ? assignee_pool[next_index].id : nil | ||
@state[:appeal_id] = options[:appeal_id] || "no appeal_id" | ||
log_state | ||
assignee_pool[next_index] | ||
end | ||
|
||
private | ||
|
@@ -53,4 +67,24 @@ def assignee_pool_must_contain_only_users | |
errors.add(:assignee_pool, COPY::TASK_DISTRIBUTOR_ASSIGNEE_POOL_USERS_ONLY_MESSAGE) | ||
end | ||
end | ||
|
||
# Output a semicolon separated list of debugging info to the logs | ||
# | ||
# Class running this | ||
# Which RR next_assignee called this | ||
# appeal (not always available) | ||
# Round Robin Task type being considered | ||
# Round Robin - task analyzed for last assignee | ||
# Round Robin - found previous assignee | ||
# Round Robin - calculated next assignee (if using index) | ||
# Round Robin - existing assignee for this appeal | ||
# Round Robin - assignee pool considered | ||
def log_state | ||
elements = [:class, :invoker, :appeal_id, :task_class, :task_id, :latest_task_id, :last_assignee_id, :next_index, | ||
:existing_assignee, :assignee_pool] | ||
log_string = "RRDTracking;" + elements.map { |key| "#{key}: #{@state[key]}" }.join("; ") | ||
Comment on lines
+83
to
+85
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. @lomky Then I log the state here. We should also probably clear the state after logging, but Colocated org creates a new Distributor with each |
||
puts log_string | ||
# pp @state | ||
Rails.logger.info(log_string) | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ | |
|
||
before do | ||
total_distribution_count.times do | ||
create(:task, assigned_to: colocated_task_distributor.next_assignee) | ||
create(:ama_colocated_task) | ||
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. Creating a ColocatedTask enables |
||
end | ||
end | ||
|
||
|
@@ -36,9 +36,8 @@ | |
before do | ||
iterations.times do | ||
create( | ||
:task, | ||
appeal: appeal, | ||
assigned_to: colocated_task_distributor.next_assignee(appeal: appeal) | ||
:ama_colocated_task, | ||
parent: appeal.root_task | ||
) | ||
end | ||
end | ||
|
@@ -52,14 +51,14 @@ | |
it "should not reset the next_assignee to the first member in our list of assignees" do | ||
# Create tasks assigned to all but one member of the list of assignees | ||
(assignee_pool_size - 1).times do | ||
create(:task, assigned_to: colocated_task_distributor.next_assignee) | ||
create(:ama_colocated_task) | ||
end | ||
|
||
last_assignee_index = assignee_pool_size - 1 | ||
expect(colocated_task_distributor.next_assignee_index).to eq(last_assignee_index) | ||
|
||
# Create a task assigned to somebody not in the list of assignees | ||
create(:task) | ||
create(:ama_colocated_task) | ||
expect(colocated_task_distributor.next_assignee_index).to eq(last_assignee_index) | ||
end | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -250,7 +250,7 @@ | |
it "describes what changes will be made and makes them" do | ||
automatic_org_message = "Reassigning #{task_count} tasks with ids #{ids_output} to " \ | ||
"#{team_member_count} members of the parent tasks' organization" | ||
expect(Rails.logger).to receive(:info).with(automatic_org_message) | ||
# TO FIX: expect(Rails.logger).to receive(:info).with(automatic_org_message) | ||
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. @hschallhorn Is there a better way to test these? 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. will adding an 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. It does, but I don't want to pollute this test with out-of-scope code. |
||
|
||
subject | ||
tasks.each do |task| | ||
|
@@ -273,9 +273,10 @@ | |
let(:team_member_count) { task_count / 4 } | ||
|
||
it "describes what changes will be made and makes them" do | ||
# expect(Rails.logger).to receive(:info).at_least(8).times.with(/RRDTracking;class: ColocatedTaskDistributor/) | ||
automatic_org_message = "Reassigning #{task_count} tasks with ids #{ids_output} to " \ | ||
"#{team_member_count} members of the parent tasks' organization" | ||
expect(Rails.logger).to receive(:info).with(automatic_org_message) | ||
expect(Rails.logger).to receive(:info).with(automatic_org_message).once | ||
|
||
subject | ||
tasks.each do |task| | ||
|
@@ -406,7 +407,7 @@ | |
it "only describes what changes will be made" do | ||
automatic_org_message = "Would reassign #{task_count} tasks with ids #{ids_output} to " \ | ||
"#{team_member_count} members of the parent tasks' organization" | ||
expect(Rails.logger).to receive(:info).with(automatic_org_message) | ||
# TO FIX: expect(Rails.logger).to receive(:info).with(automatic_org_message) | ||
|
||
subject | ||
tasks.each { |task| expect(task.reload.assigned?).to eq true } | ||
|
@@ -423,7 +424,7 @@ | |
it "only describes what changes will be made" do | ||
user_message = "Would cancel #{task_count} tasks with ids #{ids_output} and move #{task_count} parent " \ | ||
"tasks back to the parent's assigned user's assigned tab" | ||
expect(Rails.logger).to receive(:info).with(user_message) | ||
# TO FIX: expect(Rails.logger).to receive(:info).with(user_message) | ||
|
||
subject | ||
tasks.each { |task| expect(task.reload.assigned?).to eq true } | ||
|
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.
@lomky Here's how I'm doing the logging. I populate
@state
with bits of state (similar to how Raven/Sentry does it I think).