activemessaging-kestrel-adapter 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Binary file
@@ -1,3 +1,6 @@
1
+ == 0.0.4 / 2011-02-15
2
+ * Add a queue_stats method to get stats on server queues from the adapter.
3
+
1
4
  == 0.0.3 / 2011-02-05
2
5
  * Introduce a 0.1 second sleep in #receive if no subscribed queues have a message
3
6
  to avoid spin loops in the ActiveMessaging Gateway. This is a bug, IMHO, in
data/README.md CHANGED
@@ -54,13 +54,16 @@ The ability to override the policy is provided for edge cases.
54
54
  Requirements
55
55
  ------------
56
56
 
57
+ * activemessaging >= 0.7.1
57
58
  * memcached-client
58
59
 
60
+ Probably activesupport as well since activemessaging barfs if you do not
61
+ include it at the right time for certain use cases.
62
+
59
63
  Future
60
64
  ------
61
65
 
62
66
  * Handle a cluster of kestrel servers
63
- * Write some tests (need a mock kestrel service?)
64
67
 
65
68
  Install
66
69
  -------
@@ -24,7 +24,7 @@ module ActiveMessaging
24
24
  # times in the face of exceptions. Returns return result of block if
25
25
  # successful. If number of tries is exhausted, the exception is reraised.
26
26
  # Retry loop will sleep options[:delay] seconds between retries (default 5).
27
- # If you want error logging, pass in :logger. If not provided, Rails.logger
27
+ # If you want error logging, pass in :logger. If not provided, ActiveMessaging.logger
28
28
  # is used if defined.
29
29
  def do_work(options = {})
30
30
  logger = defined?(::Rails) ? ::Rails.logger : nil
@@ -58,11 +58,13 @@ module ActiveMessaging
58
58
  # Logging
59
59
  attr_accessor :logger
60
60
 
61
+ KESTREL_STATS_QUEUE_KEYS = [:items, :bytes, :total_items, :logsize, :expired_items, :mem_items, :mem_bytes, :age, :discarded, :waiters, :open_transactions] unless defined?(KESTREL_STATS_QUEUE_KEYS)
62
+
61
63
  # Create a new Kestrel adapter using the provided config
62
64
  def initialize(cfg = {})
63
65
  cfg = symbolize_keys(cfg)
64
66
  # TODO: Decide on fallback logging ...
65
- @logger = cfg.delete(:logger) || (defined?(::Rails) && ::Rails.logger ? ::Rails.logger : nil) || default_logger
67
+ @logger = cfg.delete(:logger) || ActiveMessaging.logger || (defined?(::Rails) && ::Rails.logger ? ::Rails.logger : nil) || default_logger
66
68
  @retry_policy = cfg.delete(:retry_policy) || {:strategy => SimpleRetry, :config => {:tries => 1, :delay => 5}}
67
69
  @empty_queues_delay = cfg.delete(:empty_queues_delay) || 0.1
68
70
  if @retry_policy[:strategy].is_a?(String)
@@ -75,6 +77,34 @@ module ActiveMessaging
75
77
  nil
76
78
  end
77
79
 
80
+ # Returns hash of hashes of hashes containing stats for each active queue
81
+ # in each member of the kestrel cluster.
82
+ # top level hash has following structure:
83
+ # { "server1_def" => { "queue1" => { ... }, "queue2" => { ... } },
84
+ # "server2_def" => { "queue1" => { ... }, "queue2" => { ... } } }
85
+ # "server_def" are host:port
86
+ def queue_stats
87
+ stats = @kestrel.stats
88
+ queues = stats.values.inject([]) do |queue_names, hash|
89
+ hash.keys.each do |key|
90
+ if md = /queue_(.+)_total_items/.match(key)
91
+ queue_names << md[1]
92
+ end
93
+ end
94
+ queue_names
95
+ end
96
+ stats.inject(Hash.new{|h,k| h[k] = Hash.new(&h.default_proc) }) do |return_hash, (server_def, stats_hash)|
97
+ queues.each do |queue|
98
+ KESTREL_STATS_QUEUE_KEYS.each do |key|
99
+ stats_key = "queue_#{queue}_#{key}"
100
+ denormalized_name = queue.gsub('--FS--', '/') # denormalize the name ...
101
+ return_hash[server_def][denormalized_name][key] = stats_hash[stats_key]
102
+ end
103
+ end
104
+ return_hash
105
+ end
106
+ end
107
+
78
108
  # Connect to the kestrel server using a Memcached client
79
109
  def connect
80
110
  logger.debug("Creating connection to Kestrel using config #{@config.inspect}") if logger.level <= Logger::DEBUG
@@ -1 +1 @@
1
- 0.0.3
1
+ 0.0.4
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activemessaging-kestrel-adapter
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Douglas A. Seifert
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-06 00:00:00 -08:00
18
+ date: 2011-02-15 00:00:00 -08:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -75,10 +75,12 @@ executables:
75
75
  extensions: []
76
76
 
77
77
  extra_rdoc_files:
78
+ - .README.md.swp
78
79
  - History.txt
79
80
  - README.md
80
81
  - bin/activemessaging-kestrel-adapter
81
82
  files:
83
+ - .README.md.swp
82
84
  - .bnsignore
83
85
  - History.txt
84
86
  - README.md