2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-06-18 15:46:50 -04:00
|
|
|
module Jobs
|
2019-10-02 00:01:53 -04:00
|
|
|
class PendingQueuedPostsReminder < ::Jobs::Scheduled
|
2015-06-18 15:46:50 -04:00
|
|
|
|
2022-05-04 12:33:43 -04:00
|
|
|
every 15.minutes
|
2015-06-18 15:46:50 -04:00
|
|
|
|
|
|
|
def execute(args)
|
2017-09-12 17:44:31 -04:00
|
|
|
return true unless SiteSetting.notify_about_queued_posts_after > 0
|
2015-06-18 15:46:50 -04:00
|
|
|
|
2017-05-22 16:26:18 -04: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 17:44:31 -04: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 16:26:18 -04:00
|
|
|
self.last_notified_id = queued_post_ids.max
|
2015-06-18 15:46:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def should_notify_ids
|
2019-01-03 12:03:01 -05:00
|
|
|
ReviewableQueuedPost.where(status: Reviewable.statuses[:pending]).where(
|
2022-05-04 12:33:43 -04:00
|
|
|
'created_at < ?', SiteSetting.notify_about_queued_posts_after.to_f.hours.ago
|
2019-01-03 12:03:01 -05:00
|
|
|
).pluck(:id)
|
2015-06-18 15:46:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def last_notified_id
|
2019-12-03 04:05:53 -05:00
|
|
|
(i = Discourse.redis.get(self.class.last_notified_key)) && i.to_i
|
2015-06-18 15:46:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def last_notified_id=(arg)
|
2019-12-03 04:05:53 -05:00
|
|
|
Discourse.redis.set(self.class.last_notified_key, arg)
|
2015-06-18 15:46:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.last_notified_key
|
2020-04-30 02:48:34 -04:00
|
|
|
"last_notified_queued_post_id"
|
2015-06-18 15:46:50 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|