Sha256: e50ce3d2f722c2b93c5113f8e3f57313e51f78b4e06f2a8b840abf9de73a4ad4

Contents?: true

Size: 1.75 KB

Versions: 7

Compression:

Stored size: 1.75 KB

Contents

module SimpleDeploy
  class Stack
    class Deployment
      class Status

        def initialize(args)
          @config = args[:config]
          @stack = args[:stack]
          @ssh_user = args[:ssh_user]
          @name = args[:name]
          @logger = @config.logger
        end

        def clear_for_deployment?
          !deployment_in_progress?
        end

        def clear_deployment_lock(force=false)
          if deployment_in_progress? && force
            @logger.info "Forcing. Clearing deployment status."
            unset_deployment_in_progress
          end
        end

        def deployment_in_progress?
          @logger.debug "Checking deployment status for #{@name}."
          if attributes['deployment_in_progress'] == 'true'
            @logger.info "Deployment in progress for #{@name}."
            @logger.info "Started by #{attributes['deployment_user']}@#{attributes['deployment_datetime']}."
            true
          else
            @logger.debug "No other deployments in progress for #{@name}."
            false
          end
        end

        def set_deployment_in_progress
          @logger.debug "Setting deployment in progress by #{@ssh_user} for #{@name}."
          @stack.update :attributes => [ { 'deployment_in_progress' => 'true',
                                           'deployment_user'        => @ssh_user,
                                           'deployment_datetime'    => Time.now.to_s } ]
        end

        def unset_deployment_in_progress
          @logger.debug "Clearing deployment in progress for #{@name}."
          @stack.update :attributes => [ { 'deployment_in_progress' => 'false' } ]
        end

        private

        def attributes
          @stack.attributes
        end

      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
simple_deploy-0.5.6 lib/simple_deploy/stack/deployment/status.rb
simple_deploy-0.5.5 lib/simple_deploy/stack/deployment/status.rb
simple_deploy-0.5.4 lib/simple_deploy/stack/deployment/status.rb
simple_deploy-0.5.3 lib/simple_deploy/stack/deployment/status.rb
simple_deploy-0.5.2 lib/simple_deploy/stack/deployment/status.rb
simple_deploy-0.5.1 lib/simple_deploy/stack/deployment/status.rb
simple_deploy-0.5.0 lib/simple_deploy/stack/deployment/status.rb