Get destroy job working properly and prevent misfires on updated users

This commit is contained in:
CactusPuppy 2021-04-09 10:55:46 -07:00
parent 757d16919d
commit cacb265829
No known key found for this signature in database
GPG key ID: 4B33B0A3E15E2C82
2 changed files with 7 additions and 5 deletions

View file

@ -81,9 +81,9 @@ class User < ApplicationRecord
after_save :touch_events
# after_create_commit :mailbluster_create_lead
# Note that using after_create_commit and after_update_commit does not work.
# See https://github.com/CactusPuppy/snapcon/pull/43#discussion_r609458034
after_commit :mailbluster_create_lead, on: :create
# after_destroy_commit :mailbluster_delete_lead
after_commit :mailbluster_delete_lead, on: :destroy
after_commit :mailbluster_update_lead, on: :update, if: ->(user){ ['name', 'email'].any? { |key| user.ts_saved_changes.key? key } }
@ -381,10 +381,12 @@ class User < ApplicationRecord
def mailbluster_create_lead
MailblusterCreateLeadJob.perform_later self
ts_reset_saved_changes
end
def mailbluster_delete_lead
MailblusterDeleteLeadJob.perform_later self
MailblusterDeleteLeadJob.perform_later self.email
ts_reset_saved_changes
end
def mailbluster_update_lead

View file

@ -33,8 +33,8 @@ class MailblusterManager
})
end
def self.delete_lead(user)
email_hash = Digest::MD5.hexdigest user.email
def self.delete_lead(email)
email_hash = Digest::MD5.hexdigest email
query_api(:delete, "/#{email_hash}")
end
end