Sha256: c46cbcdfd6dad4cec00dc2baa37cee0d696e74218694c11e16c580fa8552495d

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

module Pairzone
  module Api
    module PairzoneLifecycle
      attr_accessor :start_wait_interval
      DEFAULT_START_WAIT_INTERVAL = 5

      def start(options)
        Logger.info("Starting Pairzone for project '#{options[:project_name]}'...")
        pairzone = create(:project_name => options[:project_name], :collaborators => options[:collaborators])
        report_starting_status(pairzone)

        wait_for(pairzone)
      end

      def report_starting_status(pairzone)
        Logger.info("Pairzone '#{pairzone.name}' started.")
        pairzone.collaborators.each do |collaborator|
          Logger.info("Collaborator '#{collaborator}' added.")
        end
      end

      def wait_for(pairzone)
        while pairzone.status != 'started' do
          Logger.info("Waiting for pairzone to boot...")
          sleep start_wait_interval || DEFAULT_START_WAIT_INTERVAL
          pairzone = find_by_project_name(pairzone.name)
        end
        Logger.info("Pairzone booted: ip address #{pairzone.ip}")
        pairzone
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pairzone-0.0.1 lib/pairzone/api/pairzone_lifecycle.rb