Class: PlanMyStuff::Reminders::Closer

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

Overview

Auto-closes a waiting issue that has exceeded the configured inactivity_close_days ceiling. Clears waiting state and emits a dedicated plan_my_stuff.issue.closed_inactive event.

Goes through Issue#update! with skip_notification: true so the regular issue.closed event is suppressed in favor of the dedicated issue.closed_inactive. Issue#persist_update!‘s clear_waiting_state_on_close! hook handles stripping waiting labels and clearing waiting timestamps in the single save write.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Closer.

Parameters:

  • issue (PlanMyStuff::Issue)

    candidate issue from the sweep

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

    clock reference



33
34
35
36
# File 'lib/plan_my_stuff/reminders/closer.rb', line 33

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

Class Method Details

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

Returns true when the issue has waited longer than inactivity_close_days relative to now.

Parameters:

Returns:

  • (Boolean)


23
24
25
26
27
28
# File 'lib/plan_my_stuff/reminders/closer.rb', line 23

def self.should_close?(issue, now: Time.now.utc)
  start = issue..waiting_on_user_at || issue..waiting_on_approval_at
  return false if start.nil?

  ((now.utc - start) / 1.day) >= PlanMyStuff.configuration.inactivity_close_days
end

Instance Method Details

#callvoid

This method returns an undefined value.

Closes the issue, tags it with the configured user_inactive_label, then emits plan_my_stuff.issue.closed_inactive.



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/plan_my_stuff/reminders/closer.rb', line 44

def call
  @issue.update!(
    state: :closed,
    metadata: { closed_by_inactivity: true },
    skip_notification: true,
  )
  add_user_inactive_label
  PlanMyStuff::Notifications.instrument(
    'issue.closed_inactive',
    @issue,
    reason: :inactivity,
  )
end