Class: Gjallarhorn::Proxy::Manager

Inherits:
Object
  • Object
show all
Defined in:
lib/gjallarhorn/proxy/manager.rb

Overview

Base proxy manager class

Handles traffic routing and switching during deployments. Supports different proxy types (nginx, traefik, kamal-proxy) for zero-downtime deployments.

Since:

  • 0.1.0

Direct Known Subclasses

KamalProxyManager, NginxManager, TraefikManager

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, logger = nil) ⇒ Manager

Initialize proxy manager

Parameters:

  • config (Hash)

    Proxy configuration

  • logger (Logger) (defaults to: nil)

    Logger instance

Since:

  • 0.1.0



19
20
21
22
23
# File 'lib/gjallarhorn/proxy/manager.rb', line 19

def initialize(config, logger = nil)
  @config = config
  @proxy_type = config[:type] || "nginx"
  @logger = logger || Logger.new($stdout)
end

Instance Attribute Details

#configObject (readonly)

Since:

  • 0.1.0



13
14
15
# File 'lib/gjallarhorn/proxy/manager.rb', line 13

def config
  @config
end

#loggerObject (readonly)

Since:

  • 0.1.0



13
14
15
# File 'lib/gjallarhorn/proxy/manager.rb', line 13

def logger
  @logger
end

#proxy_typeObject (readonly)

Since:

  • 0.1.0



13
14
15
# File 'lib/gjallarhorn/proxy/manager.rb', line 13

def proxy_type
  @proxy_type
end

Class Method Details

.create(config, logger = nil) ⇒ Manager

Create appropriate proxy manager based on configuration

Parameters:

  • config (Hash)

    Proxy configuration

  • logger (Logger) (defaults to: nil)

    Logger instance

Returns:

  • (Manager)

    Proxy manager instance

Since:

  • 0.1.0



67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/gjallarhorn/proxy/manager.rb', line 67

def self.create(config, logger = nil)
  case config[:type]
  when "nginx"
    NginxManager.new(config, logger)
  when "traefik"
    TraefikManager.new(config, logger)
  when "kamal-proxy"
    KamalProxyManager.new(config, logger)
  else
    raise ConfigurationError, "Unsupported proxy type: #{config[:type]}"
  end
end

Instance Method Details

#healthy?Boolean

Check if proxy is healthy

Returns:

  • (Boolean)

    True if proxy is responding

Since:

  • 0.1.0



58
59
60
# File 'lib/gjallarhorn/proxy/manager.rb', line 58

def healthy?
  false # Default implementation
end

#restartBoolean

Restart proxy service

Returns:

  • (Boolean)

    True if restart successful

Since:

  • 0.1.0



50
51
52
53
# File 'lib/gjallarhorn/proxy/manager.rb', line 50

def restart
  @logger.info "Restarting #{@proxy_type} proxy..."
  false # Default implementation
end

#statusHash

Get proxy status

Returns:

  • (Hash)

    Proxy status information

Since:

  • 0.1.0



39
40
41
42
43
44
45
# File 'lib/gjallarhorn/proxy/manager.rb', line 39

def status
  {
    type: @proxy_type,
    status: "unknown",
    upstreams: []
  }
end

#switch_traffic(service_name:, from_containers:, to_container:) ⇒ void

This method is abstract.

Subclasses should implement this method

This method returns an undefined value.

Switch traffic from old containers to new container

Parameters:

  • service_name (String)

    Service name

  • from_containers (Array<Hash>)

    Containers to switch traffic from

  • to_container (Hash)

    Container to switch traffic to

Raises:

  • (NotImplementedError)

Since:

  • 0.1.0



32
33
34
# File 'lib/gjallarhorn/proxy/manager.rb', line 32

def switch_traffic(service_name:, from_containers:, to_container:)
  raise NotImplementedError, "Subclasses must implement switch_traffic"
end