2019-05-02 17:17:27 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-06-18 14:46:50 -05:00
|
|
|
module Jobs
|
2019-10-01 23:01:53 -05:00
|
|
|
class PendingQueuedPostsReminder < ::Jobs::Scheduled
|
2015-06-18 14:46:50 -05:00
|
|
|
|
|
|
|
every 1.hour
|
|
|
|
|
|
|
|
def execute(args)
|
2017-09-12 16:44:31 -05:00
|
|
|
return true unless SiteSetting.notify_about_queued_posts_after > 0
|
2015-06-18 14:46:50 -05:00
|
|
|
|
2017-05-22 15:26:18 -05:00
|
|
|
queued_post_ids = should_notify_ids
|
|
|
|
|
|
|
|
if queued_post_ids.size > 0 && last_notified_id.to_i < queued_post_ids.max
|
2017-09-12 16:44:31 -05:00
|
|
|
PostCreator.create(
|
|
|
|
Discourse.system_user,
|
|
|
|
target_group_names: Group[:moderators].name,
|
|
|
|
archetype: Archetype.private_message,
|
|
|
|
subtype: TopicSubtype.system_message,
|
|
|
|
title: I18n.t('system_messages.queued_posts_reminder.subject_template', count: queued_post_ids.size),
|
|
|
|
raw: I18n.t('system_messages.queued_posts_reminder.text_body_template', base_url: Discourse.base_url)
|
|
|
|
)
|
|
|
|
|
2017-05-22 15:26:18 -05:00
|
|
|
self.last_notified_id = queued_post_ids.max
|
2015-06-18 14:46:50 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def should_notify_ids
|
2019-01-03 11:03:01 -06:00
|
|
|
ReviewableQueuedPost.where(status: Reviewable.statuses[:pending]).where(
|
|
|
|
'created_at < ?', SiteSetting.notify_about_queued_posts_after.hours.ago
|
|
|
|
).pluck(:id)
|
2015-06-18 14:46:50 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def last_notified_id
|
|
|
|
(i = $redis.get(self.class.last_notified_key)) && i.to_i
|
|
|
|
end
|
|
|
|
|
|
|
|
def last_notified_id=(arg)
|
|
|
|
$redis.set(self.class.last_notified_key, arg)
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.last_notified_key
|
2017-05-22 15:26:18 -05:00
|
|
|
"last_notified_queued_post_id".freeze
|
2015-06-18 14:46:50 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|