lib/command/maintenance_on.rb in cpflow-3.0.1 vs lib/command/maintenance_on.rb in cpflow-4.0.0
- old
+ new
@@ -13,50 +13,16 @@
- Specify the one-off workload through `one_off_workload` in the `.controlplane/controlplane.yml` file
- Optionally specify the maintenance workload through `maintenance_workload` in the `.controlplane/controlplane.yml` file (defaults to 'maintenance')
- Maintenance mode is only supported for domains that use path based routing mode and have a route configured for the prefix '/' on either port 80 or 443
DESC
- def call # rubocop:disable Metrics/MethodLength
- one_off_workload = config[:one_off_workload]
- maintenance_workload = config.current[:maintenance_workload] || "maintenance"
+ def call
+ maintenance_mode.enable!
+ end
- domain_data = if config.domain
- cp.fetch_domain(config.domain)
- else
- cp.find_domain_for([one_off_workload, maintenance_workload])
- end
- unless domain_data
- raise "Can't find domain. " \
- "Maintenance mode is only supported for domains that use path based routing mode " \
- "and have a route configured for the prefix '/' on either port 80 or 443."
- end
+ private
- domain = domain_data["name"]
- if cp.domain_workload_matches?(domain_data, maintenance_workload)
- progress.puts("Maintenance mode is already enabled for app '#{config.app}'.")
- return
- end
-
- cp.fetch_workload!(maintenance_workload)
-
- # Start maintenance workload
- Cpflow::Cli.start(["ps:start", "-a", config.app, "-w", maintenance_workload, "--wait"])
-
- progress.puts
-
- # Switch domain workload
- step("Switching workload for domain '#{domain}' to '#{maintenance_workload}'") do
- cp.set_domain_workload(domain_data, maintenance_workload)
-
- # Give it a bit of time for the domain to update
- Kernel.sleep(30)
- end
-
- progress.puts
-
- # Stop all other workloads
- Cpflow::Cli.start(["ps:stop", "-a", config.app, "--wait"])
-
- progress.puts("\nMaintenance mode enabled for app '#{config.app}'.")
+ def maintenance_mode
+ @maintenance_mode ||= MaintenanceMode.new(self)
end
end
end