mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-28 01:56:01 -05:00
8ec7fd84fd
This commit introduces 3 queues for sidekiq "critical" for urgent jobs (weighted at 4x weight) "default" for standard jobs(weighted at 2x weight) "low" for less important jobs "critical jobs" Reset Password emails has been seperated to its own job Heartbeat which is required to keep sidekiq running Test email which needs to return real quick "low priority jobs" Notify mailing list Pull hotlinked images Update gravatar "default" All the rest Note: for people running sidekiq from command line use bin/sidekiq -q critical,4 -q default,2 -q low
61 lines
2.1 KiB
Ruby
61 lines
2.1 KiB
Ruby
module Jobs
|
|
|
|
class NotifyMailingListSubscribers < Jobs::Base
|
|
|
|
sidekiq_options queue: 'low'
|
|
|
|
def execute(args)
|
|
return if SiteSetting.disable_mailing_list_mode
|
|
|
|
post_id = args[:post_id]
|
|
post = post_id ? Post.with_deleted.find_by(id: post_id) : nil
|
|
|
|
raise Discourse::InvalidParameters.new(:post_id) unless post
|
|
return if post.trashed? || post.user_deleted? || (!post.topic)
|
|
|
|
users =
|
|
User.activated.not_blocked.not_suspended.real
|
|
.joins(:user_option)
|
|
.where(user_options: {mailing_list_mode: true})
|
|
.where('NOT EXISTS(
|
|
SELECT 1
|
|
FROM topic_users tu
|
|
WHERE
|
|
tu.topic_id = ? AND
|
|
tu.user_id = users.id AND
|
|
tu.notification_level = ?
|
|
)', post.topic_id, TopicUser.notification_levels[:muted])
|
|
.where('NOT EXISTS(
|
|
SELECT 1
|
|
FROM category_users cu
|
|
WHERE
|
|
cu.category_id = ? AND
|
|
cu.user_id = users.id AND
|
|
cu.notification_level = ?
|
|
)', post.topic.category_id, CategoryUser.notification_levels[:muted])
|
|
|
|
users.each do |user|
|
|
if Guardian.new(user).can_see?(post)
|
|
begin
|
|
if EmailLog.reached_max_emails?(user)
|
|
EmailLog.create!(
|
|
email_type: 'mailing_list',
|
|
to_address: user.email,
|
|
user_id: user.id,
|
|
post_id: post.id,
|
|
skipped: true,
|
|
skipped_reason: "[MailingList] #{I18n.t('email_log.exceeded_limit')}"
|
|
)
|
|
else
|
|
message = UserNotifications.mailing_list_notify(user, post)
|
|
Email::Sender.new(message, :mailing_list, user).send if message
|
|
end
|
|
rescue => e
|
|
Discourse.handle_job_exception(e, error_context(args, "Sending post to mailing list subscribers", { user_id: user.id, user_email: user.email }))
|
|
end
|
|
end
|
|
end
|
|
|
|
end
|
|
end
|
|
end
|