2015-06-18 15:46:50 -04:00
|
|
|
module Jobs
|
|
|
|
class PendingQueuedPostReminder < Jobs::Scheduled
|
|
|
|
|
|
|
|
every 1.hour
|
|
|
|
|
|
|
|
def execute(args)
|
|
|
|
return true unless SiteSetting.notify_about_queued_posts_after > 0 && SiteSetting.contact_email
|
|
|
|
|
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
|
|
|
|
message = PendingQueuedPostsMailer.notify(count: queued_post_ids.size)
|
2015-06-18 15:46:50 -04:00
|
|
|
Email::Sender.new(message, :pending_queued_posts_reminder).send
|
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
|
2017-05-22 16:26:18 -04:00
|
|
|
QueuedPost.new_posts.visible.where('created_at < ?', SiteSetting.notify_about_queued_posts_after.hours.ago).pluck(:id)
|
2015-06-18 15:46:50 -04: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 16:26:18 -04:00
|
|
|
"last_notified_queued_post_id".freeze
|
2015-06-18 15:46:50 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|