add slightly more logs when skipping email notifications
This commit is contained in:
parent
2af587005b
commit
4ad5660615
|
@ -6,19 +6,20 @@ module Jobs
|
|||
class UserEmail < Jobs::Base
|
||||
|
||||
def execute(args)
|
||||
notification, post = nil
|
||||
|
||||
raise Discourse::InvalidParameters.new(:user_id) unless args[:user_id].present?
|
||||
raise Discourse::InvalidParameters.new(:type) unless args[:type].present?
|
||||
|
||||
post = nil
|
||||
notification = nil
|
||||
type = args[:type]
|
||||
|
||||
user = User.find_by(id: args[:user_id])
|
||||
to_address = args[:to_address].presence || user.try(:email).presence || "no_email_found"
|
||||
|
||||
set_skip_context(type, args[:user_id], to_address)
|
||||
|
||||
set_skip_context(type, args[:user_id], args[:to_address].presence || user.try(:email).presence || "no_email_found")
|
||||
return skip(I18n.t("email_log.no_user", user_id: args[:user_id])) unless user
|
||||
|
||||
if args[:post_id]
|
||||
if args[:post_id].present?
|
||||
post = Post.find_by(id: args[:post_id])
|
||||
return skip(I18n.t('email_log.post_not_found', post_id: args[:post_id])) unless post.present?
|
||||
end
|
||||
|
@ -27,18 +28,17 @@ module Jobs
|
|||
notification = Notification.find_by(id: args[:notification_id])
|
||||
end
|
||||
|
||||
message, skip_reason = message_for_email( user,
|
||||
message, skip_reason = message_for_email(user,
|
||||
post,
|
||||
type,
|
||||
notification,
|
||||
args[:notification_type],
|
||||
args[:notification_data_hash],
|
||||
args[:email_token],
|
||||
args[:to_address] )
|
||||
|
||||
args[:to_address])
|
||||
|
||||
if message
|
||||
Email::Sender.new(message, args[:type], user).send
|
||||
Email::Sender.new(message, type, user).send
|
||||
else
|
||||
skip_reason
|
||||
end
|
||||
|
@ -113,7 +113,7 @@ module Jobs
|
|||
|
||||
# Update the to address if we have a custom one
|
||||
if message && to_address.present?
|
||||
message.to = [to_address]
|
||||
message.to = to_address
|
||||
end
|
||||
|
||||
[message, nil]
|
||||
|
@ -143,7 +143,7 @@ module Jobs
|
|||
to_address: @skip_context[:to_address],
|
||||
user_id: @skip_context[:user_id],
|
||||
skipped: true,
|
||||
skipped_reason: reason,
|
||||
skipped_reason: "[UserEmail] #{reason}",
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
@ -135,7 +135,7 @@ module Email
|
|||
|
||||
def to_address
|
||||
@to_address ||= begin
|
||||
to = @message ? @message.to : nil
|
||||
to = @message.try(:to)
|
||||
to = to.first if Array === to
|
||||
to.presence || "no_email_found"
|
||||
end
|
||||
|
@ -167,7 +167,7 @@ module Email
|
|||
to_address: to_address,
|
||||
user_id: @user.try(:id),
|
||||
skipped: true,
|
||||
skipped_reason: reason
|
||||
skipped_reason: "[Sender] #{reason}"
|
||||
)
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue