Skip to content

Commit 4bc3b3b

Browse files
committed
Add auto-cleanup job
1 parent 969996e commit 4bc3b3b

5 files changed

Lines changed: 39 additions & 0 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class AutoCloseComplaintsJob < ApplicationJob
2+
queue_as :default
3+
4+
def perform(*args)
5+
complaints = Complaint.where(status: 'reviewed')
6+
.where(Arel.sql('status_updated_at <= ?', 14.days.ago))
7+
complaints.each do |complaint|
8+
complaint.update_status 'closed'
9+
end
10+
end
11+
end

config/schedule.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
runner 'scripts/cleanup_votes.rb'
2323
end
2424

25+
every 1.day, at: '02:30' do
26+
runner 'scripts/run_complaints_closure.rb'
27+
end
28+
2529
every 6.hours do
2630
runner 'scripts/recalc_abilities.rb'
2731
end

scripts/run_complaints_closure.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
AutoCloseComplaintsJob.perform_later

test/fixtures/complaints.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,18 @@ reviewed:
4444
access_token: a84acee3-117a-4719-a5d5-72ad720bbfd7
4545
status_updated_at: <%= 1.day.ago %>
4646

47+
old_reviewed:
48+
report_type: illegal
49+
content_type: ccb
50+
reported_url: https://example.com/test
51+
user: basic_user
52+
user_wants_updates: true
53+
email: test1@example.com
54+
status: reviewed
55+
outcome: upheld
56+
access_token: cc42c90b-0503-486e-97be-e3aa92562e5c
57+
status_updated_at: <%= 15.days.ago %>
58+
4759
responded:
4860
report_type: illegal
4961
content_type: ccb
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
require 'test_helper'
2+
3+
class AutoCloseComplaintsJobTest < ActiveJob::TestCase
4+
test 'complaints auto closure works' do
5+
perform_enqueued_jobs do
6+
AutoCloseComplaintsJob.perform_later
7+
end
8+
9+
assert_equal 'closed', complaints(:old_reviewed).status
10+
end
11+
end

0 commit comments

Comments
 (0)