profit 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,20 +8,30 @@ OptionParser.new { |opts|
8
8
  opts.banner = "Usage: profit_server [options]"
9
9
 
10
10
  opts.on("-r", "--redis-address [STRING]", String,
11
- "Redis Address (127.0.0.1:6379)") do |ra|
11
+ "Redis Address (default: 127.0.0.1:6379)") do |ra|
12
12
  options[:redis_address] = ra.split(":").first
13
13
  options[:redis_port] = ra.split(":").last.to_i
14
14
  end
15
15
 
16
16
  opts.on("-z", "--zmq-address [STRING]", String,
17
- "ZMQ Address (tcp://*:5556)") do |za|
17
+ "ZMQ Address (default: tcp://*:5556)") do |za|
18
18
  options[:zmq_address] = za
19
19
  end
20
20
 
21
21
  opts.on("-n", "--pool-size [DECIMAL]", OptionParser::DecimalInteger,
22
- "Redis client pool size (10)") do |n|
22
+ "Redis client pool size (default: 10)") do |n|
23
23
  options[:pool_size] = n
24
24
  end
25
+
26
+ opts.on("-l", "--log-file-path [STRING]", String,
27
+ "Log file (default: STDOUT)") do |log|
28
+ options[:log_path] = log
29
+ end
30
+
31
+ opts.on("-v", "--log-level [LOGLEVEL]", [:error, :warn, :info, :debug],
32
+ "Log level (default: error), error|warn|info|debug") do |log_level|
33
+ options[:log_level] = log_level
34
+ end
25
35
  }.parse!
26
36
 
27
37
  Profit::Server.new(options).run
@@ -2,6 +2,7 @@ require 'zmq'
2
2
  require 'eventmachine'
3
3
  require 'em-hiredis'
4
4
  require 'json'
5
+ require 'logger'
5
6
 
6
7
  module Profit
7
8
  end
@@ -10,7 +10,12 @@ module Profit
10
10
  @options[:redis_port] = options[:redis_port] || 6379
11
11
  @options[:zmq_address] = options[:zmq_address] || "tcp://*:5556"
12
12
  @options[:pool_size] = options[:pool_size] || 10
13
+ @options[:log_path] = options[:log_path] || STDOUT
14
+ @options[:log_level] = options[:log_level] || :error
15
+
16
+ logger.level = log_level
13
17
  @ctx = ZMQ::Context.new
18
+ logger.info "Starting profit_server with options: #{@options}"
14
19
  end
15
20
 
16
21
  def run
@@ -35,8 +40,8 @@ module Profit
35
40
  metric_type = message_hash.delete("metric_type")
36
41
 
37
42
  response = conn.rpush "profit:metric:#{metric_type}", message_hash.to_json
38
- response.callback { |resp| puts "callback: #{resp}"}
39
- response.errback { |resp| puts "errback: #{resp}"}
43
+ response.callback { |resp| logger.debug "callback: #{resp}"}
44
+ response.errback { |resp| logger.error "error: #{resp}"}
40
45
  response
41
46
  end
42
47
  end
@@ -45,9 +50,24 @@ module Profit
45
50
 
46
51
  private
47
52
 
53
+ def logger
54
+ @logger ||= Logger.new(@options[:log_path])
55
+ end
56
+
57
+ def log_level
58
+ Logger.const_get(@options[:log_level].upcase)
59
+ end
60
+
48
61
  def setup_interrupt_handling
49
- trap(:INT) { EM.stop }
50
- EM.add_shutdown_hook { ctx.destroy }
62
+ trap(:INT) do
63
+ logger.debug "trap received, shutting down EM run loop."
64
+ EM.stop
65
+ end
66
+
67
+ EM.add_shutdown_hook do
68
+ logger.debug "destroying ZMQ context"
69
+ ctx.destroy
70
+ end
51
71
  end
52
72
 
53
73
  def spawn_redis_connections
@@ -1,3 +1,3 @@
1
1
  module Profit
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: profit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -155,7 +155,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
155
155
  version: '0'
156
156
  segments:
157
157
  - 0
158
- hash: -1836147071158890398
158
+ hash: -957264636356464606
159
159
  required_rubygems_version: !ruby/object:Gem::Requirement
160
160
  none: false
161
161
  requirements:
@@ -164,7 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
164
164
  version: '0'
165
165
  segments:
166
166
  - 0
167
- hash: -1836147071158890398
167
+ hash: -957264636356464606
168
168
  requirements: []
169
169
  rubyforge_project:
170
170
  rubygems_version: 1.8.23