Class: Tootsie::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/tootsie/application.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Application

Returns a new instance of Application.



5
6
7
8
9
# File 'lib/tootsie/application.rb', line 5

def initialize(options = {})
  @@instance = self
  @logger = Logger.new('/dev/null')
  @configuration = Configuration.new
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



61
62
63
# File 'lib/tootsie/application.rb', line 61

def configuration
  @configuration
end

#loggerObject (readonly)

Returns the value of attribute logger.



64
65
66
# File 'lib/tootsie/application.rb', line 64

def logger
  @logger
end

#queueObject (readonly)

Returns the value of attribute queue.



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

def queue
  @queue
end

#task_managerObject (readonly)

Returns the value of attribute task_manager.



62
63
64
# File 'lib/tootsie/application.rb', line 62

def task_manager
  @task_manager
end

Class Method Details

.getObject



56
57
58
# File 'lib/tootsie/application.rb', line 56

def get
  @@instance
end

Instance Method Details

#configure!(config_path) ⇒ Object



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
36
37
38
39
40
41
42
43
44
45
# File 'lib/tootsie/application.rb', line 11

def configure!(config_path)
  @configuration.load_from_file(config_path)
  case @configuration.log_path
    when 'syslog'
      @logger = SyslogLogger.new('tootsie')
    when String
      @logger = Logger.new(@configuration.log_path)
    else
      @logger = Logger.new($stderr)
  end
  @logger.info "Starting"

  queue_options = @configuration.queue_options ||= {}

  adapter = (queue_options[:adapter] || 'sqs').to_s
  case adapter
    when 'sqs'
      @queue = Tootsie::SqsQueue.new(
        :queue_name => queue_options[:queue],
        :access_key_id => @configuration.aws_access_key_id,
        :secret_access_key => @configuration.aws_secret_access_key,
        :max_backoff => queue_options[:max_backoff])
    when 'amqp'
      @queue = Tootsie::AmqpQueue.new(
        :host_name => queue_options[:host],
        :queue_name => queue_options[:queue],
        :max_backoff => queue_options[:max_backoff])
    when 'file'
      @queue = Tootsie::FileSystemQueue.new(queue_options[:root])
    else
      raise 'Invalid queue configuration'
  end

  @task_manager = TaskManager.new(@queue)
end

#s3_serviceObject



47
48
49
50
51
52
53
# File 'lib/tootsie/application.rb', line 47

def s3_service
  abort "AWS access key and secret required" unless
    @configuration.aws_access_key_id and @configuration.aws_secret_access_key
  return @s3_service ||= ::S3::Service.new(
    :access_key_id => @configuration.aws_access_key_id,
    :secret_access_key => @configuration.aws_secret_access_key)
end