purge old sendinblue mails
This commit is contained in:
parent
602c71f94d
commit
ddea0b9a45
2 changed files with 24 additions and 0 deletions
9
app/jobs/cron/purge_old_sib_mails_job.rb
Normal file
9
app/jobs/cron/purge_old_sib_mails_job.rb
Normal file
|
@ -0,0 +1,9 @@
|
|||
class Cron::PurgeOldSibMailsJob < Cron::CronJob
|
||||
self.schedule_expression = "every day at midnight"
|
||||
|
||||
def perform
|
||||
sib = Sendinblue::API.new
|
||||
day_to_delete = (Time.zone.today - 31.days).strftime("%Y-%m-%d")
|
||||
sib.delete_events(day_to_delete)
|
||||
end
|
||||
end
|
|
@ -55,6 +55,21 @@ class Sendinblue::API
|
|||
[]
|
||||
end
|
||||
|
||||
def delete_events(day, opts = {})
|
||||
client = ::SibApiV3Sdk::TransactionalEmailsApi.new
|
||||
event_opts = { start_date: day, end_date: day, limit: 100 }.merge(opts)
|
||||
while (events = client.get_email_event_report(event_opts).events).present?
|
||||
message_ids = events.map(&:message_id).uniq
|
||||
message_ids.each do |message_id|
|
||||
client.smtp_log_message_id_delete(message_id)
|
||||
end
|
||||
end
|
||||
true
|
||||
rescue ::SibApiV3Sdk::ApiError => e
|
||||
Rails.logger.error e.message
|
||||
false
|
||||
end
|
||||
|
||||
def unblock_user(email_address)
|
||||
client = ::SibApiV3Sdk::TransactionalEmailsApi.new
|
||||
client.smtp_blocked_contacts_email_delete(email_address)
|
||||
|
|
Loading…
Reference in a new issue