class MaintenancePlansController
Manages maintenance plans for iceberg tables: listing, viewing, editing, and controlling plans (run, pause, resume). Each action authorizes with Pundit; set_plan loads the plan for the member actions.
Public Instance Methods
Source
# File app/controllers/maintenance_plans_controller.rb, line 36 def create authorize MaintenancePlan table = IcebergTable.find(params[:maintenance_plan][:iceberg_table_id]) existing = MaintenancePlan.kept.find_by(iceberg_table: table) if existing redirect_to edit_maintenance_plan_path(existing), notice: t("plans.notices.already_exists") return end @plan = MaintenancePlan.new(plan_params.merge(iceberg_table: table)) if @plan.save redirect_to @plan, notice: t("plans.notices.created") else @tables = IcebergTable.includes(:catalog).order(:namespace, :name) render :new, status: :unprocessable_content end end
Creates a plan for the selected table. If the table already has a plan, redirects to the existing planβs edit form instead.
Source
# File app/controllers/maintenance_plans_controller.rb, line 98 def destroy authorize @plan if @plan.execution_histories.where(status: %w[pending running]).exists? redirect_to @plan, alert: t("plans.notices.destroy_blocked") return end table = @plan.iceberg_table @plan.destroy! redirect_to iceberg_table_path(table), notice: t("plans.notices.destroyed") end
Soft-deletes the plan: it disappears from every list, but the row, its steps, and the execution history all survive. A plan with a still-pending or running execution is refused, so it does not vanish mid-run.
Source
# File app/controllers/maintenance_plans_controller.rb, line 57 def edit authorize @plan ensure_all_steps_present end
Renders the edit form, ensuring every canonical step is present for editing.
Source
# File app/controllers/maintenance_plans_controller.rb, line 8 def index authorize MaintenancePlan @plans = MaintenancePlan.kept.includes(:iceberg_table, :maintenance_policy).order(:id) @pagy, @plans = pagy(@plans) end
Lists all maintenance plans with their table and policy, ordered by id.
Source
# File app/controllers/maintenance_plans_controller.rb, line 20 def new authorize MaintenancePlan @plan = MaintenancePlan.new @plan.iceberg_table_id = params.dig(:maintenance_plan, :iceberg_table_id) @plan.cron = MaintenancePlan::DEFAULT_CRON MaintenancePlan::CANONICAL_ORDER.each_with_index do |operation, position| @plan.maintenance_steps.build( operation: operation, position: position, enabled: MaintenancePlan::DEFAULT_ENABLED_STEPS.include?(operation) ) end @tables = IcebergTable.includes(:catalog).order(:namespace, :name) end
Renders the new plan form with a table selector and default steps.
Source
# File app/controllers/maintenance_plans_controller.rb, line 82 def pause authorize @plan, :pause? @plan.update!(is_paused: true) redirect_to @plan, notice: t("plans.notices.paused") end
Pauses the plan and redirects back to it.
Source
# File app/controllers/maintenance_plans_controller.rb, line 89 def resume authorize @plan, :resume? @plan.update!(is_paused: false, consecutive_failures: 0, needs_review: false) redirect_to @plan, notice: t("plans.notices.resumed") end
Resumes a paused plan, clearing failure and review state, then redirects.
Source
# File app/controllers/maintenance_plans_controller.rb, line 75 def run authorize @plan, :run? MaintenanceOrchestrator.run_plan(@plan.id, force: true) redirect_to @plan, notice: t("plans.notices.enqueued") end
Enqueues maintenance for the plan through the orchestrator and redirects.
Source
# File app/controllers/maintenance_plans_controller.rb, line 15 def show authorize @plan end
Shows a single maintenance plan.
Source
# File app/controllers/maintenance_plans_controller.rb, line 64 def update authorize @plan if @plan.update(resourced_params) redirect_to @plan, notice: t("plans.notices.updated") else ensure_all_steps_present render :edit, status: :unprocessable_content end end
Updates the plan with the submitted nested steps and redirects to the plan, or re-renders the edit form on validation failure.