-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate task timer Looker view to data integrity checker (#12428)
Resolves #12111 ### Description Ports the old Looker SQL snippet to a modern Query object. The SQL is included for reference.
- Loading branch information
Showing
9 changed files
with
108 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
app/queries/pending_incomplete_and_uncancelled_task_timers_query.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen-string-literal: true | ||
|
||
class PendingIncompleteAndUncancelledTaskTimersQuery | ||
def call | ||
TaskTimer.processable | ||
.where("task_timers.created_at < ? AND task_timers.submitted_at < ?", | ||
Time.zone.yesterday, Time.zone.yesterday - 1) | ||
end | ||
end |
19 changes: 19 additions & 0 deletions
19
app/services/pending_incomplete_and_uncancelled_task_timers_checker.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
class PendingIncompleteAndUncancelledTaskTimersChecker < DataIntegrityChecker | ||
def call | ||
return if pending_timers.count == 0 | ||
|
||
add_to_report "#{pending_timers.count} pending and incomplete TaskTimers" | ||
add_to_report "Verify TaskTimerJob is running and check each TaskTimer.error" | ||
pending_timers.each do |timer| | ||
add_to_report "TaskTimer.find(#{timer.id})" | ||
end | ||
end | ||
|
||
private | ||
|
||
def pending_timers | ||
@pending_timers ||= PendingIncompleteAndUncancelledTaskTimersQuery.new.call | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
SELECT | ||
DATE(task_timers.created_at ) AS "task_timers.created_date", | ||
task_timers.id AS "task_timers.id", | ||
DATE(task_timers.submitted_at ) AS "task_timers.submitted_date", | ||
DATE(task_timers.attempted_at ) AS "task_timers.attempted_date", | ||
task_timers.task_id AS "task_timers.task_id" | ||
FROM public.task_timers AS task_timers | ||
|
||
WHERE ((task_timers.created_at < (DATEADD(day,-1, DATE_TRUNC('day',GETDATE()) )))) AND (task_timers.processed_at IS NULL) AND (task_timers.canceled_at IS NULL) AND ((task_timers.submitted_at < (DATEADD(day,-2, DATE_TRUNC('day',GETDATE()) )))) | ||
ORDER BY 1 DESC | ||
LIMIT 500 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
FactoryBot.define do | ||
factory :task_timer do | ||
association :task, factory: :task | ||
last_submitted_at { Time.zone.now } | ||
submitted_at { Time.zone.now } | ||
end | ||
end |
17 changes: 17 additions & 0 deletions
17
spec/queries/pending_incomplete_and_uncancelled_task_timers_query_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# frozen_string_literal: true | ||
|
||
describe PendingIncompleteAndUncancelledTaskTimersQuery do | ||
describe "#call" do | ||
let(:task) { create(:task) } | ||
let!(:task_timer) do | ||
create(:task_timer, task: task, created_at: 5.days.ago, submitted_at: 6.days.ago) | ||
end | ||
let!(:task_timer2) do | ||
create(:task_timer, task: task) | ||
end | ||
|
||
it "finds incomplete task timers" do | ||
expect(subject.call).to eq([task_timer]) | ||
end | ||
end | ||
end |
19 changes: 19 additions & 0 deletions
19
spec/services/pending_incomplete_and_uncancelled_task_timers_checker_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
describe PendingIncompleteAndUncancelledTaskTimersChecker do | ||
describe "#call" do | ||
let(:task) { create(:task) } | ||
let!(:task_timer) do | ||
create(:task_timer, task: task, created_at: 5.days.ago, submitted_at: 6.days.ago) | ||
end | ||
let!(:task_timer2) { create(:task_timer, task: task) } | ||
|
||
it "sends a message to Slack when there are pending incomplete and uncancelled Task Timers" do | ||
subject.call | ||
|
||
expect(subject.report?).to eq(true) | ||
expect(subject.report).to match("1 pending and incomplete") | ||
expect(subject.slack_channel).to eq("#appeals-job-alerts") | ||
end | ||
end | ||
end |