Skip to content
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

Handle edge cases for EvidenceSubmissionWindowTasks #15598

Merged
merged 4 commits into from
Nov 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/models/concerns/asyncable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module Asyncable
# These column names can be overridden in consuming classes as needed.
class_methods do
REQUIRES_PROCESSING_WINDOW_DAYS = 4
EXPIRATION_WINDOW_BUFFER_HOURS = 1
DEFAULT_REQUIRES_PROCESSING_RETRY_WINDOW_HOURS = 3
PROCESS_DELAY_VBMS_OFFSET_HOURS = 7

Expand Down Expand Up @@ -205,7 +206,7 @@ def expired_without_processing?
last_submitted = self[self.class.last_submitted_at_column]
return false unless last_submitted

last_submitted < self.class.requires_processing_until
last_submitted < (self.class.requires_processing_until + self.class::EXPIRATION_WINDOW_BUFFER_HOURS.hours)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Called here:

timer.restart! if timer.expired_without_processing?

ensures we catch any timers that will have slipped outside of this 4 day window by the time the next job is run

end

def submitted_and_ready?
Expand Down
42 changes: 35 additions & 7 deletions spec/models/concerns/timeable_task_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,21 @@ def timer_ends_at
end
end

class EdgeCaseTimedTask < Task
include TimeableTask
include CurrentDate

def when_timer_ends; end

def timer_ends_at
# Our task timer job runs every hour. On occasion we create task timers that should have expired 3.99999 days ago
# so they are not caught by the initial expired_without_processing? check when they are created. However, by the
# time the job has run, the task should have expired 4.000001 days ago and falls out of our
# expired_without_processing scope. See https://github.com/department-of-veterans-affairs/caseflow/issues/15245
4.days.ago + 30.minutes
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

weird time stuff math. + 30.minutes moves the completion time of this task to just under 4 days ago (3.979 days ago to be exact)

end
end

before do
Timecop.freeze(now)
end
Expand All @@ -54,13 +69,26 @@ def timer_ends_at
expect(timers.first.submitted_at).to eq(task.timer_ends_at)
end

it "queues itself immediately when the delay is in the past" do
task = OldTimedTask.create!(appeal: appeal, assigned_to: Bva.singleton)
timers = TaskTimer.where(task: task)
expect(timers.length).to eq(1)
expect(timers.first.submitted_and_ready?).to eq(true)
expect(timers.first.submitted_at).to eq(task.timer_ends_at)
expect(timers.first.last_submitted_at).to eq(now)
shared_examples "resets the timer" do
it "queues itself immediately when the delay is in the past" do
timers = TaskTimer.where(task: task)
expect(timers.length).to eq(1)
expect(timers.first.submitted_and_ready?).to eq(true)
expect(timers.first.submitted_at).to eq(task.timer_ends_at)
expect(timers.first.last_submitted_at).to eq(now)
end
end

context "when the delay is in the past" do
let(:task) { OldTimedTask.create!(appeal: appeal, assigned_to: Bva.singleton) }

it_behaves_like "resets the timer"
end

context "when the delay is judge barely less than four days in the past" do
let(:task) { EdgeCaseTimedTask.create!(appeal: appeal, assigned_to: Bva.singleton) }

it_behaves_like "resets the timer"
end

context "when not correctly configured" do
Expand Down