Module: Skippable

Extended by:
ActiveSupport::Concern
Included in:
Jobs::GroupSmtpEmail, Jobs::NotifyMailingListSubscribers, Jobs::UserEmail
Defined in:
app/jobs/concerns/skippable.rb

Instance Method Summary collapse

Instance Method Details

#create_skipped_email_log(email_type:, to_address:, user_id:, post_id:, reason_type:) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/jobs/concerns/skippable.rb', line 6

def create_skipped_email_log(email_type:, to_address:, user_id:, post_id:, reason_type:)
  attributes = {
    email_type: email_type,
    to_address: to_address,
    user_id: user_id,
    post_id: post_id,
    reason_type: reason_type,
  }

  if reason_type == SkippedEmailLog.reason_types[:exceeded_emails_limit]
    exists =
      SkippedEmailLog.exists?(
        { created_at: (Time.zone.now.beginning_of_day..Time.zone.now.end_of_day) }.merge!(
          attributes.except(:post_id),
        ),
      )

    return if exists
  end

  SkippedEmailLog.create!(attributes)
end