Module: PlanMyStuff::Pipeline::CompletedSweep

Defined in:
lib/plan_my_stuff/pipeline/completed_sweep.rb

Overview

Removes pipeline project items that have been at Completed for longer than the configured TTL.

Driven by RemindersSweepJob so the gem ships one scheduled entrypoint. Items are removed via Pipeline.remove! so subscribers see the standard plan_my_stuff.pipeline.removed event.

Class Method Summary collapse

Class Method Details

.perform(project_number: nil, now: Time.current) ⇒ Array<PlanMyStuff::ProjectItem>

Runs the sweep. No-op when configuration.pipeline_completion_purge_enabled is false.

Parameters:

  • project_number (Integer, nil) (defaults to: nil)
  • now (Time) (defaults to: Time.current)

Returns:



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/plan_my_stuff/pipeline/completed_sweep.rb', line 23

def perform(project_number: nil, now: Time.current)
  config = PlanMyStuff.configuration
  return [] unless config.pipeline_completion_purge_enabled

  number = PlanMyStuff::Pipeline.resolve_pipeline_project_number(project_number)
  project = PlanMyStuff::Project.find(number)

  completed_status = PlanMyStuff::Pipeline.resolve_status_name(
    PlanMyStuff::Pipeline::Status::COMPLETED,
  )
  ttl = config.pipeline_completion_ttl_hours.hours

  candidates = project.items.select do |item|
    item.status == completed_status &&
      item.updated_at.present? &&
      item.updated_at + ttl < now
  end

  candidates.each { |item| PlanMyStuff::Pipeline.remove!(item) }
  candidates
end