Module: Familia::Features::Housekeeping

Defined in:
lib/familia/features/housekeeping.rb

Overview

Housekeeping registers named cleanup chores on a Horreum class and runs them against a single instance. It is intended for short-lived, repeated tidying of fields whose values have drifted (e.g. running nightly for a few days, then removing the chore once data is clean).

The feature owns registration and per-instance execution only. Iteration, batching, scheduling, error aggregation, and persistence are the caller's responsibility.

Example:

class Organization < Familia::Horreum feature :housekeeping field :planid

chore :standardize_planid do |org|
  canonical = case org.planid
              when 'pro', 'Pro', 'professional_v1' then 'professional'
              when 'free', 'Free', 'basic'         then 'free'
              end
  if canonical && canonical != org.planid
    org.planid = canonical
    org.save
    true
  end
end

end

org = Organization.from_identifier('acme-corp') org.do_chores! # => { standardize_planid: true }

org.do_chore!(:standardize_planid) # => true

org.tidy! # alias for do_chores! # => { standardize_planid: true }

See docs/guides/feature-housekeeping.md for the full guide.

Defined Under Namespace

Modules: ModelClassMethods, ModelInstanceMethods

Constant Summary collapse

DEFAULT_BATCH_SIZE =

Default Redis-pipelined batch size for run_chores!. Each batch hits Redis once via load_multi, then drives the chore block per record. 100 trades pipeline efficiency against per-batch latency.

100