class MaintenancePolicy
Reusable maintenance rule, applicable to N tables at once.
Motivation: with 100+ tables, creating plans by hand becomes hundreds of forms. A policy (“streaming: optimize every 6h”) applied in bulk solves that, and editing the policy syncs every plan derived from it.
A policy defines the WHOLE chain: cron, which steps enter, and each step’s configuration (steps_config).
Public Instance Methods
Source
# File app/models/maintenance_policy.rb, line 18 def apply_to!(tables) created = 0 updated = 0 skipped = 0 tables.each do |table| plan = MaintenancePlan.kept.find_or_initialize_by(iceberg_table: table) if plan.maintenance_policy_id.nil? || plan.maintenance_policy_id == id new_record = plan.new_record? plan.cron = cron plan.maintenance_policy = self plan.save! sync_steps(plan) new_record ? created += 1 : updated += 1 else skipped += 1 end end { created: created, updated: updated, skipped: skipped } end
Creates (or updates) the maintenance PLAN of each given table. Never steals a plan that already belongs to another policy.
Source
# File app/models/maintenance_policy.rb, line 44 def propagate! maintenance_plans.each do |plan| plan.update!(cron: cron) sync_steps(plan) end maintenance_plans.size end
Reapplies cron and step configuration to the plans already derived from this policy. Does NOT touch is_paused: a pause from repeated failures is operational information and must not be wiped by a policy edit.