fare 0.1.4 → 0.1.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 19284af00a69196303261e5f9ed526c44f5148d7
4
- data.tar.gz: ab17ec672508a98d779150174aea1b31e48c735d
3
+ metadata.gz: 132b90179b7fd7df7ec8cc62eca402f173e83aac
4
+ data.tar.gz: 848631e42f06ede13aa9ff9594de1ceec6538886
5
5
  SHA512:
6
- metadata.gz: dc6d680546cc48699b9fc6bd93c0c3ab0184e56c0d20746adb6d0dd14a433b974b01c8eb0a8e79a89dc0b388826033db3a883ef81999c091f7e8399a3d561c9d
7
- data.tar.gz: 382058f8efad2a7e10441514527c315ca1d2a18383e8715ea0f89021f41edf2e31f6ec1bc55138580897a30fcbd24fc01beff903f21ab4731dc7fbe5dcfe0712
6
+ metadata.gz: 2276e4db0c56de7ad437c85f99324b7f531b300bd6b5f47c57d3c56976faa10e0d5daf53bbb18fd1d2a7cb8e823ca9b4c34ab825f7540803c03dcde962be56b9
7
+ data.tar.gz: 7dede1a297d9da395b71480d61ddf141511ff07cebee00240cf95d66982e802a2efd83a93ee997cd15277be1cafdff72ada426ac38cb1334bb084f0468a2722c
@@ -1,17 +1,24 @@
1
1
  require "timeout"
2
+ require "thread"
2
3
 
3
4
  module Fare
4
5
  class Subscriber
5
6
  UnknownSubscriber = Class.new(ArgumentError)
6
7
 
8
+ BUSY_MUTEX = Mutex.new
9
+
7
10
  attr_reader :configuration
8
11
 
9
12
  def initialize(configuration, options = {})
10
- name = (options[:name] || configuration.app_name).to_s
11
- subscriber_config = configuration.fetch_subscriber(name)
13
+ @configuration = configuration
14
+ @name = (options[:name] || configuration.app_name).to_s
15
+ subscriber_config = configuration.fetch_subscriber(@name)
12
16
  subscriber_config.load_setup
13
- @sqs_queue = configuration.fetch_subscriber_queue(name)
17
+ @sqs_queue = configuration.fetch_subscriber_queue(@name)
14
18
  @stacks = subscriber_config.stacks
19
+ @concurrency = options.fetch(:concurrency, 1)
20
+ @busy = 0
21
+ set_program_name
15
22
  end
16
23
 
17
24
  def produce(queue)
@@ -24,6 +31,7 @@ module Fare
24
31
  end
25
32
 
26
33
  def consume(message)
34
+ increment_busy
27
35
  event = Event.deserialize(message.body)
28
36
  @stacks.each do |stack|
29
37
  if stack.handles?(event)
@@ -31,6 +39,35 @@ module Fare
31
39
  end
32
40
  end
33
41
  message.delete
42
+ ensure
43
+ decrement_busy
44
+ end
45
+
46
+ private
47
+
48
+ def set_program_name
49
+ pattern = "fare subscriber (app: %{app}; queue: %{queue}; version: %{version}; busy: %{busy}/%{concurrency}; fare: %{fare_version})"
50
+
51
+ str = pattern % {
52
+ app: configuration.app_name.to_s,
53
+ queue: @name,
54
+ version: configuration.app_version,
55
+ busy: @busy,
56
+ concurrency: @concurrency,
57
+ fare_version: ::Fare::VERSION,
58
+ }
59
+
60
+ $PROGRAM_NAME = str
61
+ end
62
+
63
+ def increment_busy
64
+ BUSY_MUTEX.synchronize { @busy += 1 }
65
+ set_program_name
66
+ end
67
+
68
+ def decrement_busy
69
+ BUSY_MUTEX.synchronize { @busy -= 1 }
70
+ set_program_name
34
71
  end
35
72
 
36
73
  end
@@ -65,6 +65,7 @@ module Fare
65
65
 
66
66
  parser.on "-c", "--concurrency NUM", Integer, "Set the number of threads (default: #{daemon_options[:concurrency]}" do |concurrency|
67
67
  daemon_options[:concurrency] = concurrency
68
+ subscriber_options[:concurrency] = concurrency
68
69
  end
69
70
 
70
71
  parser.on "-P", "--pid FILE", "The location of the PID file (required when daemonizing)" do |pid|
@@ -176,6 +177,7 @@ module Fare
176
177
 
177
178
  parser.on "-c", "--concurrency NUM", Integer, "Set the number of threads (default: #{daemon_options[:concurrency]}" do |concurrency|
178
179
  daemon_options[:concurrency] = concurrency
180
+ subscriber_options[:concurrency] = concurrency
179
181
  end
180
182
 
181
183
  parser.on "-P", "--pid FILE", "The location of the PID file (required)" do |pid|
@@ -1,3 +1,3 @@
1
1
  module Fare
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fare
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - iain
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-12 00:00:00.000000000 Z
11
+ date: 2014-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk