discourse/app/jobs/scheduled/auto_queue_handler.rb
Loïc Guitaut 26fe047724 DEV: Use AR enums in reviewables related code
This is the first patch of many to replace our custom enums in Ruby by
the ones provided by `ActiveRecord`.
2022-09-22 14:44:27 +02:00

29 lines
840 B
Ruby

# frozen_string_literal: true
# This job will automatically act on records that have gone unhandled on a
# queue for a long time.
module Jobs
class AutoQueueHandler < ::Jobs::Scheduled
every 1.day
def execute(args)
return unless SiteSetting.auto_handle_queued_age.to_i > 0
Reviewable
.pending
.where('created_at < ?', SiteSetting.auto_handle_queued_age.to_i.days.ago)
.each do |reviewable|
if reviewable.is_a?(ReviewableFlaggedPost)
reviewable.perform(Discourse.system_user, :ignore, expired: true)
elsif reviewable.is_a?(ReviewableQueuedPost)
reviewable.perform(Discourse.system_user, :reject_post)
elsif reviewable.is_a?(ReviewableUser)
reviewable.perform(Discourse.system_user, :delete_user)
end
end
end
end
end