Module: Houston

Extended by:
Extensions
Defined in:
lib/houston/cli.rb,
lib/houston/try.rb,
lib/houston/version.rb,
lib/houston/adapters.rb,
lib/houston/boot/timer.rb,
lib/houston/boot/actions.rb,
lib/houston/test_helpers.rb,
lib/houston/boot/observer.rb,
lib/houston/boot/triggers.rb,
app/concerns/houston/props.rb,
lib/houston/boot/daemonize.rb,
lib/houston/boot/extensions.rb,
lib/houston/boot/running_as.rb,
lib/houston/boot/serializer.rb,
lib/houston/params_serializer.rb,
lib/houston/boot/configuration.rb,
lib/houston/boot/active_record_serializer.rb,
lib/houston/boot/readonly_hash_serializer.rb

Defined Under Namespace

Modules: Adapters, Extensions, Props, TestHelpers Classes: Actions, ActiveRecordSerializer, CLI, ColorValue, Configuration, DuplicateTriggerError, MissingConfiguration, Module, NotConfigured, Observer, ParamsSerializer, ReadonlyHash, ReadonlyHashSerializer, Serializer, Timer, Trigger, Triggers

Constant Summary collapse

VERSION =
"0.8.3"

Instance Attribute Summary

Attributes included from Extensions

#events, #serializers

Class Method Summary collapse

Methods included from Extensions

accept_credentials_for, add_navigation_renderer, add_project_column, add_project_feature, add_project_header_command, add_project_option, add_serializer, add_user_option, available_navigation_renderers, available_project_features, get_navigation_renderer, get_project_feature, get_registered_event, project_columns, project_header_commands, project_options, register_event, register_events, registered_event?, test_connection_to, user_credentials_support_services, user_options

Class Method Details

.actionsObject



541
542
543
# File 'lib/houston/boot/configuration.rb', line 541

def actions
  config.actions
end

.config(&block) ⇒ Object



524
525
526
527
528
529
530
531
# File 'lib/houston/boot/configuration.rb', line 524

def config(&block)
  @configuration ||= Configuration.new
  if block_given?
    @configuration.instance_eval(&block)
    @configuration.validate!
  end
  @configuration
end

.daemonize(name) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/houston/boot/daemonize.rb', line 3

def self.daemonize(name)
  unless Houston.running_as_web_server? or ENV["HOUSTON_DAEMONS"].to_s.split(",").member?(name)
    puts "\e[94m[daemon:#{name}] Skipping daemon since we're not running as a server\e[0m" if Rails.env.development?
    Rails.logger.info "\e[94m[daemon:#{name}] Skipping daemon since we're not running as a server\e[0m"
    return
  end

  puts "\e[94m[daemon:#{name}] Connecting\e[0m" if Rails.env.development?
  Rails.logger.info "\e[94m[daemon:#{name}] Connecting\e[0m"
  Thread.new do
    begin
      connected_at = Time.now
      Houston.observer.fire "daemon:#{name}:start"
      yield

    rescue Exception
      puts "\e[91m#{$!.class}: #{$!.message}\e[0m" if Rails.env.development?
      Houston.report_exception $!
      unless (Time.now - connected_at) < 60
        Houston.observer.fire "daemon:#{name}:restart"
        retry
      end
    end

    # This should never happen
    puts "\e[31m[daemon:#{name}] Disconnected\e[0m" if Rails.env.development?
    Rails.logger.error "\e[31m[daemon:#{name}] Disconnected\e[0m"

    # http://stackoverflow.com/a/3516003/731300
    Rails.logger.flush
    Houston.observer.fire "daemon:#{name}:stop"
  end
end

.deprecation_notice(message, stack_offset = 1) ⇒ Object



14
15
16
17
# File 'lib/houston/boot/configuration.rb', line 14

def deprecation_notice(message, stack_offset=1)
  message = message.gsub /<b>(.*)<\/b>/, "\e[1m\\1\e[0;34m"
  puts "\e[34mDEPRECATION: #{message}\e[0;90m\n#{caller[stack_offset]}\e[0m\n\n"
end

.observerObject



537
538
539
# File 'lib/houston/boot/configuration.rb', line 537

def observer
  config.observer
end

.reconnect(options = {}) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/houston/try.rb', line 26

def self.reconnect(options={})
  max_tries = options.fetch(:max_tries, 2)
  tries = 1
  begin
    yield
  rescue exceptions_wrapping(PG::ConnectionBad)
    ActiveRecord::Base.connection.reconnect!
    retry unless (tries += 1) > 2
    raise
  end
end

.rootObject



549
550
551
# File 'lib/houston/boot/configuration.rb', line 549

def root
  config.root
end

.running_asObject



16
17
18
# File 'lib/houston/boot/running_as.rb', line 16

def self.running_as
  @__process_type ||= discover_process_type
end

.server?Boolean

Returns:

  • (Boolean)


11
12
13
14
# File 'lib/houston/boot/running_as.rb', line 11

def self.server?
  Houston.deprecation_notice "Houston.server? is deprecated; use Houston.running_as_web_server?"
  running_as_web_server?
end

.timerObject



545
546
547
# File 'lib/houston/boot/configuration.rb', line 545

def timer
  config.timer
end

.triggersObject



533
534
535
# File 'lib/houston/boot/configuration.rb', line 533

def triggers
  config.triggers
end

.try(options, *rescue_from) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/houston/try.rb', line 3

def self.try(options, *rescue_from)
  options = { max_tries: options } if options.is_a?(Fixnum)
  options = {} unless options.is_a?(Hash)
  max_tries = options.fetch :max_tries, 3
  base = options.fetch :base, 2
  ignore = options.fetch :ignore, false
  rescue_from = [StandardError] if rescue_from.empty?

  tries = 1
  begin
    yield tries
  rescue *rescue_from
    if tries > max_tries
      return if ignore
      raise
    end
    Rails.logger.warn "\e[31m[try] \e[1m#{$!.class}\e[0;31m: #{$!.message}\e[0m"
    sleep base ** tries
    tries += 1
    retry
  end
end