Module: WithReminders
- Extended by:
- ActiveSupport::Concern
- Includes:
- WithPgLock
- Included in:
- User
- Defined in:
- app/models/concerns/with_reminders.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #build_reminder ⇒ Object
- #remind! ⇒ Object
- #should_remind? ⇒ Boolean
-
#try_remind_with_lock! ⇒ Object
Try to send a reminder, by acquiring a database lock for update the appropriate record.
Methods included from WithPgLock
Instance Method Details
#build_reminder ⇒ Object
5 6 7 8 9 10 |
# File 'app/models/concerns/with_reminders.rb', line 5 def build_reminder mailer = UserMailer.new last_submission_date.nil? ? mailer.no_submissions_reminder(self) : mailer.we_miss_you_reminder(self, cycles_since(last_submission_date)) end |
#remind! ⇒ Object
12 13 14 15 |
# File 'app/models/concerns/with_reminders.rb', line 12 def remind! build_reminder.deliver_now update! last_reminded_date: Time.now end |
#should_remind? ⇒ Boolean
17 18 19 |
# File 'app/models/concerns/with_reminders.rb', line 17 def should_remind? reminder_due? && (has_no_submissions? || has_no_recent_submission?) end |
#try_remind_with_lock! ⇒ Object
Try to send a reminder, by acquiring a database lock for update the appropriate record. This object can’t be updated as long as the reminder is being sent.
This method is aimed to be sent across multiple servers or processed concurrently and still not send duplicate mails
27 28 29 |
# File 'app/models/concerns/with_reminders.rb', line 27 def try_remind_with_lock! with_pg_lock proc { remind! }, proc { should_remind? } end |