Module: Flamingo

Defined in:
lib/flamingo.rb,
lib/flamingo/meta.rb,
lib/flamingo/wader.rb,
lib/flamingo/config.rb,
lib/flamingo/stream.rb,
lib/flamingo/version.rb,
lib/flamingo/dispatcher.rb,
lib/flamingo/web/server.rb,
lib/flamingo/stats/events.rb,
lib/flamingo/subscription.rb,
lib/flamingo/logging/utils.rb,
lib/flamingo/stream_params.rb,
lib/flamingo/dispatch_queue.rb,
lib/flamingo/daemon/pid_file.rb,
lib/flamingo/daemon/flamingod.rb,
lib/flamingo/stats/connection.rb,
lib/flamingo/logging/event_log.rb,
lib/flamingo/logging/formatter.rb,
lib/flamingo/daemon/trap_keeper.rb,
lib/flamingo/stats/rate_counter.rb,
lib/flamingo/daemon/child_process.rb,
lib/flamingo/daemon/wader_process.rb,
lib/flamingo/daemon/dispatcher_process.rb,
lib/flamingo/daemon/web_server_process.rb

Defined Under Namespace

Modules: Daemon, Logging, Stats, Web Classes: Config, DispatchQueue, Dispatcher, Meta, Stream, StreamParams, Subscription, Wader

Constant Summary collapse

Version =
VERSION = '0.4.0'

Class Method Summary collapse

Class Method Details

.configObject



63
64
65
# File 'lib/flamingo.rb', line 63

def config
  @config
end

.configure!(cfg_info = nil, validate = true) ⇒ Object

Configures flamingo. This must be called prior to using any flamingo classes.

The config argument may be one of: 1) nil: Try to locate a config file in ./flamingo.yml, ~/flamingo.yml 2) String: A config file name (preferred) 3) Flamingo::Config: Used as the configuration directly 4) Hash: Converted to a Flamingo::Config and used as the configuration



48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/flamingo.rb', line 48

def configure!(cfg_info=nil,validate=true)
  if cfg_info.nil? || cfg_info.kind_of?(String)
    config_file = find_config_file(cfg_info)
    @config = Flamingo::Config.load(config_file)
    logger.info "Loaded config file from #{config_file}"
  elsif cfg_info.kind_of?(Flamingo::Config)
    @config = cfg_info
  elsif cfg_info.kind_of?(Hash)
    @config = Flamingo::Config.new(cfg_info)
  end
  validate_config!
  # Ensure redis gets loaded
  redis
end

.connection_statsObject



112
113
114
# File 'lib/flamingo.rb', line 112

def connection_stats
  @connection_stats ||= Stats::Connection.new
end

.dispatch_queueObject



100
101
102
# File 'lib/flamingo.rb', line 100

def dispatch_queue
  @dispatch_queue ||= DispatchQueue.new(redis)
end

.event_statsObject



108
109
110
# File 'lib/flamingo.rb', line 108

def event_stats
  @event_stats ||= Stats::Events.new
end

.loggerObject



88
89
90
# File 'lib/flamingo.rb', line 88

def logger
  @logger ||= new_logger
end

.logger=(logger) ⇒ Object



92
93
94
# File 'lib/flamingo.rb', line 92

def logger=(logger)
  @logger = logger
end

.metaObject



104
105
106
# File 'lib/flamingo.rb', line 104

def meta
  @meta ||= Meta.new(redis)
end

.namespaceObject



96
97
98
# File 'lib/flamingo.rb', line 96

def namespace
  config.redis.namespace(:flamingo)
end

.new_event_logObject



116
117
118
119
120
121
122
# File 'lib/flamingo.rb', line 116

def new_event_log
  if event_config = config.logging.event(nil) 
    Logging::EventLog.new(event_config.dir,event_config.size(0))
  else
    nil
  end
end

.reconnect!Object

Intended to be called after a fork so that we don’t have issues with shared file descriptors, sockets, etc



126
127
128
129
130
131
132
# File 'lib/flamingo.rb', line 126

def reconnect!
  # Reload logger
  logger.close
  self.logger = new_logger
  reconnect_redis_client(@redis)      
  reconnect_redis_client(Resque.redis)
end

.redisObject

Returns the current Redis connection. If none has been created, will create a new one.



82
83
84
85
86
# File 'lib/flamingo.rb', line 82

def redis
  return @redis if @redis
  self.redis = config.redis.host('localhost:6379')
  self.redis
end

.redis=(server) ⇒ Object

server must be a “hostname:port” string



70
71
72
73
74
75
76
77
78
# File 'lib/flamingo.rb', line 70

def redis=(server)
  host, port, db = server.split(':')
  redis = Redis.new(:host => host, :port => port,
    :thread_safe=>true, :db => db)
  @redis = Redis::Namespace.new(namespace, :redis => redis)
  
  # Ensure resque is configured to use this redis as well
  Resque.redis = server
end