Class: Neptuno::CLI::Activate
- Includes:
- TTY::Config
- Defined in:
- lib/neptuno/cli/activate.rb
Overview
Init Neptuno files
Constant Summary
Constants included from TTY::Config
TTY::Config::ABORT_MESSAGE, TTY::Config::TTY
Constants included from TTY::File
TTY::File::ABORT_MESSAGE, TTY::File::TTY
Constants inherited from Base
Constants included from TTY::Command
TTY::Command::TTY, TTY::Command::TTYP
Constants included from TTY::Prompt
Instance Method Summary collapse
Methods included from TTY::Config
#auto_restart_procs, #config, #configured_services, #docker_compose_hash, #docker_compose_services, #get_dependants, #healthy_services, #json_services_status, #running_services, #services, #services_with_procs, #starting_services
Methods included from TTY::File
#file, #in_service?, #make_service_files, #neptuno_path, #project, #service
Methods inherited from Base
#command_service_to, #command_services_to, #initialize
Methods included from TTY::Command
#command, #command_p, #neptuno_command
Methods included from TTY::Prompt
Constructor Details
This class inherits a constructor from Neptuno::CLI::Base
Instance Method Details
#call(services: [], **options) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/neptuno/cli/activate.rb', line 14 def call(services: [], **) multi_spinner = ::TTY::Spinner::Multi.new("[:spinner] Services") spinners = {} count = 0 command_services_to("activate to services", all: .fetch(:all), services_as_args: services) do |services| system("cd #{neptuno_path} && docker compose up -d #{services.join(" ")}") running_services = ::Neptuno::CLI::List.new.running_services.first.keys running_services.sort.each do |service| spinners[service] ||= multi_spinner.register("[:spinner] :state #{service}") spinners[service].update(state: "- ") spinners[service].auto_spin end loop do ps = `cd #{neptuno_path} && docker compose ps`.split("\n").compact.select { |x| x.match(/^\s*#{project}/) } running_services.sort.each do |service| service_ps = ps.find { |s| s =~ /#{project}[-_]#{service}[-_]\d\s/ } status = :dead if service_ps.to_s.include?("exited") status = :starting if service_ps.to_s.include?("starting") status = :unhealthy if service_ps.to_s.include?("(unhealthy") status = :healthy if service_ps.to_s.include?("(healthy") status = :force if .fetch(:force) case status when :force spinners[service].success `cd #{neptuno_path}/procfiles/#{service} && overmind start -D -N > /dev/null 2>&1` when :dead spinners[service].update(state: "dead ") spinners[service].error when :starting spinners[service].update(state: "starting ") when :unhealthy spinners[service].update(state: "unhealthy ") spinners[service].error if spinners[service].instance_variable_get(:@state) == :spinning && count > 50 when :healthy spinners[service].update(state: "ready ") spinners[service].success `cd #{neptuno_path}/procfiles/#{service} && overmind start -D -N > /dev/null 2>&1` else spinners[service].update(state: "down ") spinners[service].error end end break if spinners.values.map { |s| s.instance_variable_get(:@state) }.uniq.all?(:stopped) count += 1 sleep(5) end spinner = ::TTY::Spinner.new("Neptuno: Starting[:spinner]", format: :dots) spinner.auto_spin spinner.stop end end |