<commit_before>require 'timeout'

module KumoDockerCloud
  class Stack
    attr_reader :stack_name, :app_name, :options

    #TODO delete options
    def initialize(app_name, env_name, options = { contactable: true })
      @app_name = app_name
      @stack_name = "#{app_name}-#{env_name}"
      @options = options
    end

    def deploy(service_name, version, checker = ServiceChecker.new)
      validate_params(service_name, 'Service name')
      validate_params(version, 'Version')

      service = Service.new(stack_name, service_name)
      service.deploy(version)
      checker.verify(service)
    end

    def deploy_blue_green(service_names, version, checker = ServiceChecker.new)
      haproxy_service = HaproxyService.new(@stack_name)

      services = service_names.map { |name| Service.new(stack_name, name) }
      ordered_deployment(services).each do |service|
        begin
          haproxy_service.disable_service(service)
          service.deploy(version)
          checker.verify(service)
        rescue HAProxyStateError
          raise ServiceDeployError.new("Unable to place service #{service.name} into maintainance mode on HAProxy.")
        rescue ServiceDeployError => e
          haproxy_service.disable_service(service)
          raise ServiceDeployError.new("Deployment or verification of service #{service.name} failed with message: #{e.message}")
        end<commit_msg>Bubble up error messages from HAProxyService during a blue/green deploy<commit_after>require 'timeout'

module KumoDockerCloud
  class Stack
    attr_reader :stack_name, :app_name, :options

    #TODO delete options
    def initialize(app_name, env_name, options = { contactable: true })
      @app_name = app_name
      @stack_name = "#{app_name}-#{env_name}"
      @options = options
    end

    def deploy(service_name, version, checker = ServiceChecker.new)
      validate_params(service_name, 'Service name')
      validate_params(version, 'Version')

      service = Service.new(stack_name, service_name)
      service.deploy(version)
      checker.verify(service)
    end

    def deploy_blue_green(service_names, version, checker = ServiceChecker.new)
      haproxy_service = HaproxyService.new(@stack_name)

      services = service_names.map { |name| Service.new(stack_name, name) }
      ordered_deployment(services).each do |service|
        begin
          haproxy_service.disable_service(service)
          service.deploy(version)
          checker.verify(service)
        rescue HAProxyStateError => e
          raise ServiceDeployError.new("Unable to place service #{service.name} into maintainance mode on HAProxy with message: #{e.message}")
        rescue ServiceDeployError => e
          haproxy_service.disable_service(service)
          raise ServiceDeployError.new("Deployment or verification of service #{service.name} failed with message: #{e.message}")
        end
{'fraction_non_alphanumeric': 0.08877374784110535, 'fraction_numerical': 0.0, 'mean_word_length': 3.4553846153846153, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2735796', 'n_tokens_mistral': 826, 'n_tokens_neox': 824, 'n_words': 192}