Class: PlanMyStuff::Reminders::Fire

Inherits:
Object
  • Object
show all
Defined in:
lib/plan_my_stuff/reminders/fire.rb

Overview

Emits plan_my_stuff.issue.reminder_due for a single waiting issue and advances its next_reminder_at to the next milestone in the effective reminder_days schedule (or nil when the last milestone has passed).

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(issue, now: Time.now.utc) ⇒ Fire

Returns a new instance of Fire.

Parameters:

  • issue (PlanMyStuff::Issue)

    candidate issue from the sweep

  • now (Time) (defaults to: Time.now.utc)

    clock reference (defaults to Time.now.utc)



26
27
28
29
# File 'lib/plan_my_stuff/reminders/fire.rb', line 26

def initialize(issue, now: Time.now.utc)
  @issue = issue
  @now = now.utc
end

Class Method Details

.ready?(issue, now: Time.now.utc) ⇒ Boolean

Returns true when the issue has a next_reminder_at in the past relative to now.

Parameters:

Returns:

  • (Boolean)


18
19
20
21
# File 'lib/plan_my_stuff/reminders/fire.rb', line 18

def self.ready?(issue, now: Time.now.utc)
  due = issue..next_reminder_at
  due.present? && due <= now
end

Instance Method Details

#callvoid

This method returns an undefined value.

Emits the reminder event and advances the schedule.



35
36
37
38
39
40
41
42
43
# File 'lib/plan_my_stuff/reminders/fire.rb', line 35

def call
  payload = build_payload
  PlanMyStuff::Notifications.instrument('issue.reminder_due', @issue, **payload)

  @issue.update!(
    metadata: { next_reminder_at: next_reminder_at_value },
    skip_notification: true,
  )
end