tootsie 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -210,14 +210,14 @@ Installation
210
210
  Running
211
211
  =======
212
212
 
213
- Create a configuration under `config`, eg. `config/development.yml`:
213
+ Create a configuration, eg. `tootsie.conf`:
214
214
 
215
215
  ---
216
216
  aws_access_key_id: <your Amazon key>
217
217
  aws_secret_access_key: <your Amazon secret>
218
218
  sqs_queue_name: tootsie
219
219
 
220
- Start the task manager with `bin/tootsie_task_manager start`. You can specify the number of workers with `-n`.
220
+ Start the task manager with `tootsie_task_manager -c tootsie.conf start`.
221
221
 
222
222
  To run the web service, you will need a Rack-compatible web server, such as Unicorn or Thin. To start with Thin on port 9090:
223
223
 
@@ -3,31 +3,24 @@
3
3
  $:.unshift(File.expand_path('../../lib', __FILE__))
4
4
  require 'tootsie'
5
5
 
6
- environment = ENV['RACK_ENV']
7
- environment ||= :development
8
-
9
6
  num_workers = 4
10
- logger = nil
7
+ config_path = nil
8
+ log_target = 'syslog'
11
9
 
12
10
  ARGV.options do |opts|
13
11
  opts.banner = "Usage: #{File.basename($0)} [OPTIONS] [start | stop | restart | status]"
14
12
  opts.separator ""
15
- opts.on("-e", "--environment=env", String,
16
- "Environment to run in (default: #{environment})") do |value|
17
- environment = value
18
- end
19
13
  opts.on("-n", "--num-workers=WORKERS", Integer,
20
14
  "Specify number of workers to fork (defaults to #{num_workers}.") do |value|
21
15
  num_workers = [1, value.to_i].max
22
16
  end
17
+ opts.on("-c", "--config=PATH", String,
18
+ "Specify configuration path.") do |value|
19
+ config_path = value
20
+ end
23
21
  opts.on("-l TARGET", "--logger TARGET", String,
24
22
  "Log to TARGET, which is either a file name or 'syslog'.") do |value|
25
- if value == 'syslog'
26
- require 'syslog_logger'
27
- logger = SyslogLogger.new('tootsie')
28
- else
29
- logger = Logger.new(value)
30
- end
23
+ log_target = value
31
24
  end
32
25
  opts.on("-h", "--help", "Show this help message.") do
33
26
  puts opts
@@ -40,6 +33,18 @@ ARGV.options do |opts|
40
33
  end
41
34
  end
42
35
 
36
+ unless config_path
37
+ abort 'Configuration file not specified.'
38
+ end
39
+ config_path = File.expand_path(config_path)
40
+
41
+ case log_target
42
+ when 'syslog'
43
+ logger = SyslogLogger.new('tootsie')
44
+ else
45
+ logger = Logger.new(log_target)
46
+ end
47
+
43
48
  controller = Tootsie::Daemon.new(
44
49
  :root => File.join(File.dirname(__FILE__), "/.."),
45
50
  :pid_file => File.join(File.dirname(__FILE__), "/../tmp/task_manager.pid"),
@@ -54,10 +59,8 @@ controller.on_spawn do
54
59
  Signal.trap('TERM') do
55
60
  exit(2)
56
61
  end
57
- app = Tootsie::Application.new(
58
- :environment => environment,
59
- :logger => controller.logger)
60
- app.configure!
62
+ app = Tootsie::Application.new(:logger => controller.logger)
63
+ app.configure!(config_path)
61
64
  begin
62
65
  app.task_manager.run!
63
66
  rescue SystemExit, Interrupt
@@ -1,19 +1,15 @@
1
- require 's3'
2
- require 'sqs'
3
-
4
1
  module Tootsie
5
2
 
6
3
  class Application
7
4
 
8
5
  def initialize(options = {})
9
6
  @@instance = self
10
- @environment = options[:environment] || :development
11
7
  @logger = options[:logger] || Logger.new($stderr)
12
8
  @configuration = Configuration.new
13
9
  end
14
10
 
15
- def configure!
16
- @configuration.load_from_file(File.join(Dir.pwd, "config/#{@environment}.yml"))
11
+ def configure!(config_path)
12
+ @configuration.load_from_file(config_path)
17
13
  @queue = Tootsie::SqsQueue.new(@configuration.sqs_queue_name, sqs_service)
18
14
  @task_manager = TaskManager.new(@queue)
19
15
  end
@@ -35,9 +31,7 @@ module Tootsie
35
31
  @@instance
36
32
  end
37
33
  end
38
-
39
- attr_accessor :environment
40
-
34
+
41
35
  attr_reader :configuration
42
36
  attr_reader :task_manager
43
37
  attr_reader :queue
@@ -1,3 +1,3 @@
1
1
  module Tootsie
2
- VERSION = '0.9.1'
2
+ VERSION = '0.9.2'
3
3
  end
data/lib/tootsie.rb CHANGED
@@ -1,4 +1,8 @@
1
1
  require 'active_support/core_ext/hash'
2
+ require 'syslog_logger'
3
+ require 's3'
4
+ require 'sqs'
5
+ require 'yaml'
2
6
 
3
7
  require 'tootsie/application'
4
8
  require 'tootsie/client'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tootsie
3
3
  version: !ruby/object:Gem::Version
4
- hash: 57
4
+ hash: 63
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
- - 1
10
- version: 0.9.1
9
+ - 2
10
+ version: 0.9.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alexander Staubo