purge old friend requests

a background worker to periodically remove friend requests that
have not been accepted and are more than a week ago
This commit is contained in:
Nuwan 2024-04-07 11:34:04 +05:30
parent af1140fa05
commit 9eb8c97706
3 changed files with 27 additions and 0 deletions

View File

@ -83,6 +83,10 @@ module JamRuby
return friend_request
end
def self.purgeable_requests
FriendRequest.where("status IS NULL AND created_at < ?", 1.week.ago)
end
private
def self.validate_friend_request(friend_request, user_id, friend_id)
friend_requests = FriendRequest.where("user_id='#{user_id}' AND friend_id='#{friend_id}'")

View File

@ -0,0 +1,18 @@
module JamRuby
class FriendRequestCleaner
extend Resque::Plugins::JamLonelyJob
@queue = :friend_request_cleaner
@@log = Logging.logger[FriendRequestCleaner]
def self.perform
@@log.debug("waking up")
FriendRequest.purgeable_requests do |request|
request.destroy
end
@@log.debug("done")
end
end
end

View File

@ -104,3 +104,8 @@ TallyAffiliates:
cron: "0 0,4,8,12,16,20 * * *"
class: "JamRuby::TallyAffiliates"
description: "Tallies up affiliate totals"
FriendRequestCleaner:
cron: "0 3 * * *"
class: "JamRuby::FriendRequestCleaner"
description: "Purge old friend requests that have not been accepted"