Class: Capistrano::DataPlaneApi::Deploy::Group

Inherits:
Object
  • Object
show all
Defined in:
lib/capistrano/data_plane_api/deploy/group.rb

Overview

Class which deploys the app to all servers in a particular HAProxy backend/group.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Group

: (Args) -> void



18
19
20
21
22
23
# File 'lib/capistrano/data_plane_api/deploy/group.rb', line 18

def initialize(args)
  @args = args
  @deployment_stats = T.let(DeploymentStats.new, DeploymentStats)
  @backend = T.let(nil, T.nilable(Configuration::Backend))
  @servers = T.let(nil, T.nilable(T::Array[Configuration::Server]))
end

Class Method Details

.call(args) ⇒ Object

: (Args) -> Symbol



12
13
14
# File 'lib/capistrano/data_plane_api/deploy/group.rb', line 12

def call(args)
  new(args).call
end

Instance Method Details

#callObject

Whether the deployment has been successful : -> Symbol



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
# File 'lib/capistrano/data_plane_api/deploy/group.rb', line 27

def call
  @backend = ::Capistrano::DataPlaneApi.find_backend(T.must(@args.group))
  @servers = servers(@backend)
  start_deployment

  state = :pending
  @servers&.each do |server|
    server_stats = @deployment_stats[T.must(server.name)]
    puts COLORS.bold.blue("Deploying the app to `#{server.stage}` -- `#{@backend.name}:#{server.name}`")

    puts @args.humanized_deploy_command(server.stage)
    puts

    next if @args.test?

    server_stats.start_time = ::Time.now
    deploy_command = @args.deploy_command(server.stage)
    case system deploy_command
    when true
      state = :success
    when false
      state = :failed
    when nil
      state = :pending
    end

    server_stats.end_time = ::Time.now
    server_stats.state = state

    next if state == :success

    puts COLORS.bold.red("Command `#{deploy_command}` failed")
    break
  end

  return :pending if @args.test?

  finish_deployment(state: state)
  print_summary
  state
end