m_queue 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.
- data/.document +5 -0
- data/.gitignore +5 -0
- data/LICENSE +20 -0
- data/MIT-LICENSE +20 -0
- data/README +25 -0
- data/README.rdoc +7 -0
- data/Rakefile +62 -0
- data/VERSION +1 -0
- data/examples/messenger.rb +20 -0
- data/init.rb +17 -0
- data/install.rb +1 -0
- data/lib/m_queue/daemon.rb +56 -0
- data/lib/m_queue/protocols/sparrow.rb +103 -0
- data/lib/m_queue/protocols/sqs.rb +57 -0
- data/lib/m_queue/protocols.rb +5 -0
- data/lib/m_queue/queue.rb +129 -0
- data/lib/m_queue.rb +11 -0
- data/m_queue.gemspec +70 -0
- data/tasks/m_queue_tasks.rake +28 -0
- data/test/m_queue_test.rb +7 -0
- data/test/test_helper.rb +10 -0
- data/test_mqueue.rb +15 -0
- metadata +99 -0
data/.document
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 michael
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 Alex MacCaw
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
MQueue
|
2
|
+
======
|
3
|
+
|
4
|
+
A client for Sparrow
|
5
|
+
http://code.google.com/p/sparrow/
|
6
|
+
|
7
|
+
Example
|
8
|
+
=======
|
9
|
+
|
10
|
+
class MyQueue < MQueue::Queue
|
11
|
+
def on_message(args)
|
12
|
+
puts "Received msg with args: #{args.inspect}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
servers = [
|
17
|
+
MQueue::Protocols::Sparrow.new({:host => 'localhost', :port => 11212, :weight => 1})
|
18
|
+
]
|
19
|
+
|
20
|
+
MyQueue.servers = servers
|
21
|
+
MyQueue.publish 'test'
|
22
|
+
MyQueue.run
|
23
|
+
|
24
|
+
|
25
|
+
Copyright (c) 2008 Alex MacCaw, released under the MIT license
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
|
8
|
+
gem.name = "m_queue"
|
9
|
+
gem.summary = %Q{MQueue Client Library extracted from Sparrow}
|
10
|
+
gem.email = "ma@zive.at"
|
11
|
+
gem.homepage = "http://github.com/michael/m_queue"
|
12
|
+
gem.authors = ["michael"]
|
13
|
+
|
14
|
+
gem.add_dependency 'sparrow', '>= 0.4.1'
|
15
|
+
gem.add_dependency 'sqs', '>= 0.1.2'
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
Jeweler::GemcutterTasks.new
|
20
|
+
|
21
|
+
rescue LoadError
|
22
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
23
|
+
end
|
24
|
+
|
25
|
+
require 'rake/testtask'
|
26
|
+
Rake::TestTask.new(:test) do |test|
|
27
|
+
test.libs << 'lib' << 'test'
|
28
|
+
test.pattern = 'test/**/*_test.rb'
|
29
|
+
test.verbose = true
|
30
|
+
end
|
31
|
+
|
32
|
+
begin
|
33
|
+
require 'rcov/rcovtask'
|
34
|
+
Rcov::RcovTask.new do |test|
|
35
|
+
test.libs << 'test'
|
36
|
+
test.pattern = 'test/**/*_test.rb'
|
37
|
+
test.verbose = true
|
38
|
+
end
|
39
|
+
rescue LoadError
|
40
|
+
task :rcov do
|
41
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
task :default => :test
|
47
|
+
|
48
|
+
require 'rake/rdoctask'
|
49
|
+
Rake::RDocTask.new do |rdoc|
|
50
|
+
if File.exist?('VERSION.yml')
|
51
|
+
config = YAML.load(File.read('VERSION.yml'))
|
52
|
+
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
53
|
+
else
|
54
|
+
version = ""
|
55
|
+
end
|
56
|
+
|
57
|
+
rdoc.rdoc_dir = 'rdoc'
|
58
|
+
rdoc.title = "m_queue #{version}"
|
59
|
+
rdoc.rdoc_files.include('README*')
|
60
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
61
|
+
end
|
62
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.3
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require 'rubygems'
|
3
|
+
|
4
|
+
EXAMPLES_ROOT = Pathname(__FILE__).dirname.expand_path
|
5
|
+
require EXAMPLES_ROOT.parent + 'lib/m_queue'
|
6
|
+
|
7
|
+
class QuotesQueue < MQueue::Queue
|
8
|
+
def on_message(args)
|
9
|
+
puts "Received msg with args: #{args.inspect}"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
servers = [
|
14
|
+
MQueue::Protocols::Sparrow.new({:host => 'localhost', :port => 11212, :weight => 1})
|
15
|
+
]
|
16
|
+
|
17
|
+
|
18
|
+
QuotesQueue.servers = servers
|
19
|
+
QuotesQueue.publish({:baby => "sex"})
|
20
|
+
QuotesQueue.publish 'hook'
|
data/init.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# Include hook code here
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
$:.unshift(File.dirname(__FILE__))
|
5
|
+
|
6
|
+
require 'lib/m_queue'
|
7
|
+
require 'lib/daemon'
|
8
|
+
require 'lib/protocols'
|
9
|
+
require 'lib/queue'
|
10
|
+
|
11
|
+
Dir.glob(File.join(File.dirname(__FILE__), 'lib', 'protocols', '*.rb')) {|i|
|
12
|
+
begin
|
13
|
+
require i
|
14
|
+
rescue LoadError
|
15
|
+
# Might not have sqs/beanstalk-client
|
16
|
+
end
|
17
|
+
}
|
data/install.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Install hook code here
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module MQueue
|
2
|
+
class Daemon
|
3
|
+
PID_DIR = File.join(MQUEUE_ROOT, 'tmp', 'pids')
|
4
|
+
class << self
|
5
|
+
|
6
|
+
def daemonize!(name)
|
7
|
+
fork do
|
8
|
+
Process.setsid
|
9
|
+
exit if fork
|
10
|
+
store_pid(Process.pid, name)
|
11
|
+
Dir.chdir File.dirname(__FILE__)
|
12
|
+
puts "created PID: #{Process.pid}"
|
13
|
+
File.umask 0000
|
14
|
+
STDIN.reopen "/dev/null"
|
15
|
+
STDOUT.reopen "/dev/null", "a"
|
16
|
+
STDERR.reopen STDOUT
|
17
|
+
trap("TERM") { exit }
|
18
|
+
yield if block_given?
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def kill!(name)
|
23
|
+
Dir[pid_path(name)].each do |f|
|
24
|
+
begin
|
25
|
+
puts f
|
26
|
+
pid = IO.read(f).chomp.to_i
|
27
|
+
FileUtils.rm f
|
28
|
+
Process.kill(15, pid) # TERM
|
29
|
+
puts "killed PID: #{pid}"
|
30
|
+
rescue => e
|
31
|
+
puts "Failed to kill! #{f}: #{e}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
true
|
35
|
+
end
|
36
|
+
|
37
|
+
def kill_all!
|
38
|
+
kill!('*')
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def store_pid(pid, name)
|
44
|
+
FileUtils.mkdir_p(PID_DIR)
|
45
|
+
File.open(pid_path(name), 'w'){|f|
|
46
|
+
f.write("#{pid}\n")
|
47
|
+
}
|
48
|
+
end
|
49
|
+
|
50
|
+
def pid_path(queue_name)
|
51
|
+
File.join(PID_DIR, "poller.#{queue_name}.pid")
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'socket'
|
2
|
+
|
3
|
+
module MQueue
|
4
|
+
module Protocols
|
5
|
+
class Sparrow
|
6
|
+
attr_accessor :options
|
7
|
+
|
8
|
+
LOG_DIR = File.join(MQueue::MQUEUE_ROOT, 'log')
|
9
|
+
|
10
|
+
CR = "\r\n"
|
11
|
+
ERROR = "error"
|
12
|
+
|
13
|
+
GET = "get"
|
14
|
+
SET = "set"
|
15
|
+
DELETE = "delete"
|
16
|
+
FLUSH_ALL = "flush_all"
|
17
|
+
|
18
|
+
CLIENT_ERROR_REGEX = /\ACLIENT_ERROR\s/i
|
19
|
+
SERVER_ERROR_REGEX = /\ASERVER_ERROR\s/i
|
20
|
+
ERROR_REGEX = /\AERROR\s/i
|
21
|
+
VALUE_REGEX = /^VALUE (.+) (.+) (.+)/
|
22
|
+
|
23
|
+
def initialize(opts = {})
|
24
|
+
self.options = opts
|
25
|
+
end
|
26
|
+
|
27
|
+
def []=(queue_name, msg)
|
28
|
+
send_msg SET, queue_name, 0, 0, msg.length, CR + msg
|
29
|
+
return unless @socket
|
30
|
+
@socket.gets # STORED
|
31
|
+
end
|
32
|
+
|
33
|
+
def [](queue_name)
|
34
|
+
send_msg GET, queue_name
|
35
|
+
return unless @socket
|
36
|
+
rsp = @socket.gets
|
37
|
+
return unless rsp =~ VALUE_REGEX
|
38
|
+
bytes = rsp.split(' ').last.to_i
|
39
|
+
rsp =~ /(\d+)\r/
|
40
|
+
msg = @socket.read $1.to_i
|
41
|
+
@socket.gets # CR
|
42
|
+
@socket.gets # END
|
43
|
+
msg
|
44
|
+
rescue => e
|
45
|
+
mark_dead(e)
|
46
|
+
nil
|
47
|
+
end
|
48
|
+
|
49
|
+
def delete(queue_name)
|
50
|
+
send_msg DELETE, queue_name
|
51
|
+
return unless @socket
|
52
|
+
@socket.gets
|
53
|
+
end
|
54
|
+
|
55
|
+
def delete!
|
56
|
+
send_msg FLUSH_ALL
|
57
|
+
return unless @socket
|
58
|
+
@socket.gets
|
59
|
+
end
|
60
|
+
|
61
|
+
# MQueue Protocol API
|
62
|
+
|
63
|
+
def alive?
|
64
|
+
(!@retry or @retry < Time.now)
|
65
|
+
end
|
66
|
+
|
67
|
+
def weight
|
68
|
+
options[:weight] || 0
|
69
|
+
end
|
70
|
+
|
71
|
+
def reload!
|
72
|
+
@retry = nil
|
73
|
+
@socket.close if @socket && !@socket.closed?
|
74
|
+
@socket = nil
|
75
|
+
@status = "Reloading"
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
|
80
|
+
def retry?
|
81
|
+
((@retry and @retry < Time.now) and !@connected) ? true : false
|
82
|
+
end
|
83
|
+
|
84
|
+
def send_msg(*msg)
|
85
|
+
@socket ||= TCPSocket.open(options[:host], options[:port])
|
86
|
+
@socket.print(msg.join(' ') + CR)
|
87
|
+
@socket.flush
|
88
|
+
# sleep 0.00001
|
89
|
+
rescue => e
|
90
|
+
mark_dead(e)
|
91
|
+
raise ConnectionError
|
92
|
+
end
|
93
|
+
|
94
|
+
def mark_dead( reason="Unknown error" )
|
95
|
+
@socket.close if @socket && !@socket.closed?
|
96
|
+
@socket = nil
|
97
|
+
@retry = Time::now + ( 30 + rand(10) )
|
98
|
+
@status = "DEAD: %s: Will reincarnate at %s" %
|
99
|
+
[ reason, @retry ]
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'sqs'
|
2
|
+
|
3
|
+
module MQueue
|
4
|
+
module Protocols
|
5
|
+
class SQS
|
6
|
+
attr_accessor :options
|
7
|
+
|
8
|
+
def initialize(opts = {})
|
9
|
+
self.options = opts
|
10
|
+
end
|
11
|
+
|
12
|
+
def []=(queue_name, msg)
|
13
|
+
queue(queue_name).send_message(msg)
|
14
|
+
msg
|
15
|
+
rescue => e
|
16
|
+
raise ConnectionError
|
17
|
+
end
|
18
|
+
|
19
|
+
def [](queue_name)
|
20
|
+
msg = queue(queue_name).receive_message
|
21
|
+
msg.body if msg
|
22
|
+
end
|
23
|
+
|
24
|
+
def delete(queue_name)
|
25
|
+
queue(queue_name).delete!
|
26
|
+
end
|
27
|
+
|
28
|
+
def delete!
|
29
|
+
::SQS.each_queue do |q|
|
30
|
+
q.delete!
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# MQueue Protocol API
|
35
|
+
|
36
|
+
def alive?
|
37
|
+
true
|
38
|
+
end
|
39
|
+
|
40
|
+
def weight
|
41
|
+
options[:weight] || 0
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def queue(queue_name)
|
47
|
+
@queues ||= {}
|
48
|
+
@queues[queue_name] ||=
|
49
|
+
begin
|
50
|
+
::SQS.get_queue(queue_name)
|
51
|
+
rescue ::SQS::UnavailableQueue
|
52
|
+
::SQS.create_queue(queue_name)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,129 @@
|
|
1
|
+
module MQueue
|
2
|
+
class Queue
|
3
|
+
class MQueueError < StandardError; end #:nodoc:
|
4
|
+
class NoServersLeft < MQueueError; end #:nodoc:
|
5
|
+
@@queues = []
|
6
|
+
|
7
|
+
LOG_DIR = File.join(MQUEUE_ROOT, 'log')
|
8
|
+
|
9
|
+
class << self
|
10
|
+
def inherited(subclass)
|
11
|
+
@@queues << subclass
|
12
|
+
end
|
13
|
+
|
14
|
+
def queues
|
15
|
+
@@queues
|
16
|
+
end
|
17
|
+
|
18
|
+
def run
|
19
|
+
num_sleeps = 0
|
20
|
+
loop do
|
21
|
+
msg = poll
|
22
|
+
self.new.process(msg) if msg
|
23
|
+
if !msg
|
24
|
+
if num_sleeps < 50
|
25
|
+
num_sleeps += 1
|
26
|
+
num_sleeps *= 2
|
27
|
+
end
|
28
|
+
sleep 2 #num_sleeps
|
29
|
+
else
|
30
|
+
num_sleeps = 0
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def publish(msg)
|
36
|
+
if defined?(RAILS_ENV) &&
|
37
|
+
(RAILS_ENV == 'development' or
|
38
|
+
RAILS_ENV == 'test')
|
39
|
+
return self.new.on_message(msg)
|
40
|
+
end
|
41
|
+
send_to_server {|server|
|
42
|
+
server[queue_name] = msg.to_yaml
|
43
|
+
}
|
44
|
+
msg
|
45
|
+
end
|
46
|
+
|
47
|
+
def poll
|
48
|
+
send_to_server(true) {|server|
|
49
|
+
begin
|
50
|
+
server[queue_name]
|
51
|
+
rescue => e
|
52
|
+
puts e
|
53
|
+
end
|
54
|
+
}
|
55
|
+
end
|
56
|
+
|
57
|
+
def queue_name
|
58
|
+
self.name
|
59
|
+
end
|
60
|
+
|
61
|
+
def servers=(srvs)
|
62
|
+
@@servers = srvs
|
63
|
+
end
|
64
|
+
|
65
|
+
def servers
|
66
|
+
@@servers ||= []
|
67
|
+
end
|
68
|
+
|
69
|
+
def reload!
|
70
|
+
servers.each do |s|
|
71
|
+
s.reload! if s.respond_to?('reload!')
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
def send_to_server(random = false, &block)
|
78
|
+
srvs = random ? unsorted_servers : sorted_servers
|
79
|
+
srvs.each do |server|
|
80
|
+
begin
|
81
|
+
return yield(server)
|
82
|
+
rescue => e
|
83
|
+
# Server will be marked dead
|
84
|
+
next
|
85
|
+
end
|
86
|
+
end
|
87
|
+
raise NoServersLeft
|
88
|
+
end
|
89
|
+
|
90
|
+
def alive_servers
|
91
|
+
servers.select {|a| a.alive? }.sort_by {|b| rand }
|
92
|
+
end
|
93
|
+
alias unsorted_servers alive_servers
|
94
|
+
|
95
|
+
def sorted_servers
|
96
|
+
alive_servers.sort_by {|b| b.weight }.reverse
|
97
|
+
end
|
98
|
+
|
99
|
+
end # self
|
100
|
+
|
101
|
+
def process(msg)
|
102
|
+
reload!
|
103
|
+
begin
|
104
|
+
on_message(YAML.load(msg))
|
105
|
+
rescue => e
|
106
|
+
#logger.error "\n#{ e.message } - (#{ e.class })\n" <<
|
107
|
+
# "#{(e.backtrace or []).join("\n")}"
|
108
|
+
puts "\n#{ e.message } - (#{ e.class })\n" <<
|
109
|
+
"#{(e.backtrace or []).join("\n")}"
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def logger
|
114
|
+
return @logger if @logger
|
115
|
+
FileUtils.mkdir_p(LOG_DIR)
|
116
|
+
@logger = Logger.new(File.join(LOG_DIR, self.class.queue_name + '.log'))
|
117
|
+
@logger
|
118
|
+
end
|
119
|
+
|
120
|
+
def on_message(msg)
|
121
|
+
raise 'You must implement on_message.'
|
122
|
+
end
|
123
|
+
|
124
|
+
def reload!
|
125
|
+
ActiveRecord::Base.verify_active_connections! if defined?(ActiveRecord)
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
end
|
data/lib/m_queue.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
module MQueue
|
2
|
+
MQUEUE_ROOT = defined?(Merb.root) ? Merb.root : File.join(File.dirname(__FILE__))
|
3
|
+
end
|
4
|
+
|
5
|
+
dir = Pathname(__FILE__).dirname.expand_path + 'm_queue'
|
6
|
+
|
7
|
+
require dir + 'queue'
|
8
|
+
require dir + 'daemon'
|
9
|
+
require dir + 'protocols'
|
10
|
+
require dir + 'protocols/sparrow'
|
11
|
+
require dir + 'protocols/sqs'
|
data/m_queue.gemspec
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{m_queue}
|
8
|
+
s.version = "0.1.3"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["michael"]
|
12
|
+
s.date = %q{2009-12-30}
|
13
|
+
s.email = %q{ma@zive.at}
|
14
|
+
s.extra_rdoc_files = [
|
15
|
+
"LICENSE",
|
16
|
+
"README",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"MIT-LICENSE",
|
24
|
+
"README",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"examples/messenger.rb",
|
29
|
+
"init.rb",
|
30
|
+
"install.rb",
|
31
|
+
"lib/m_queue.rb",
|
32
|
+
"lib/m_queue/daemon.rb",
|
33
|
+
"lib/m_queue/protocols.rb",
|
34
|
+
"lib/m_queue/protocols/sparrow.rb",
|
35
|
+
"lib/m_queue/protocols/sqs.rb",
|
36
|
+
"lib/m_queue/queue.rb",
|
37
|
+
"m_queue.gemspec",
|
38
|
+
"tasks/m_queue_tasks.rake",
|
39
|
+
"test/m_queue_test.rb",
|
40
|
+
"test/test_helper.rb",
|
41
|
+
"test_mqueue.rb"
|
42
|
+
]
|
43
|
+
s.homepage = %q{http://github.com/michael/m_queue}
|
44
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
45
|
+
s.require_paths = ["lib"]
|
46
|
+
s.rubygems_version = %q{1.3.5}
|
47
|
+
s.summary = %q{MQueue Client Library extracted from Sparrow}
|
48
|
+
s.test_files = [
|
49
|
+
"test/m_queue_test.rb",
|
50
|
+
"test/test_helper.rb",
|
51
|
+
"examples/messenger.rb"
|
52
|
+
]
|
53
|
+
|
54
|
+
if s.respond_to? :specification_version then
|
55
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
56
|
+
s.specification_version = 3
|
57
|
+
|
58
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
59
|
+
s.add_runtime_dependency(%q<sparrow>, [">= 0.4.1"])
|
60
|
+
s.add_runtime_dependency(%q<sqs>, [">= 0.1.2"])
|
61
|
+
else
|
62
|
+
s.add_dependency(%q<sparrow>, [">= 0.4.1"])
|
63
|
+
s.add_dependency(%q<sqs>, [">= 0.1.2"])
|
64
|
+
end
|
65
|
+
else
|
66
|
+
s.add_dependency(%q<sparrow>, [">= 0.4.1"])
|
67
|
+
s.add_dependency(%q<sqs>, [">= 0.1.2"])
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
namespace :queue do
|
2
|
+
task :start => [:environment] do
|
3
|
+
if qn = ENV['QUEUE_NAME']
|
4
|
+
queue = qn.classify.constantize
|
5
|
+
puts "Starting up #{queue.queue_name}"
|
6
|
+
MQueue::Daemon.daemonize!(queue.queue_name) { queue.run }
|
7
|
+
else
|
8
|
+
MQueue::Queue.queues.each do |queue|
|
9
|
+
puts "Starting up #{queue.queue_name}"
|
10
|
+
MQueue::Daemon.daemonize!(queue.queue_name) { queue.run }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
task :stop => [:environment] do
|
16
|
+
if qn = ENV['QUEUE_NAME']
|
17
|
+
queue = qn.classify.constantize
|
18
|
+
puts "Killing #{queue.queue_name}"
|
19
|
+
MQueue::Daemon.kill!(queue.queue_name)
|
20
|
+
else
|
21
|
+
puts "Killing all queues"
|
22
|
+
MQueue::Daemon.kill_all!
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
task :restart => [:stop, :start] do
|
27
|
+
end
|
28
|
+
end
|
data/test/test_helper.rb
ADDED
data/test_mqueue.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'lib/m_queue'
|
2
|
+
|
3
|
+
class MyQueue < MQueue::Queue
|
4
|
+
def on_message(args)
|
5
|
+
puts "Received msg with args: #{args.inspect}"
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
servers = [
|
10
|
+
MQueue::Protocols::Sparrow.new({:host => 'localhost', :port => 11212, :weight => 1})
|
11
|
+
]
|
12
|
+
|
13
|
+
MyQueue.servers = servers
|
14
|
+
MyQueue.publish 'test'
|
15
|
+
MyQueue.run
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: m_queue
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- michael
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-12-30 00:00:00 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: sparrow
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.4.1
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: sqs
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.1.2
|
34
|
+
version:
|
35
|
+
description:
|
36
|
+
email: ma@zive.at
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- LICENSE
|
43
|
+
- README
|
44
|
+
- README.rdoc
|
45
|
+
files:
|
46
|
+
- .document
|
47
|
+
- .gitignore
|
48
|
+
- LICENSE
|
49
|
+
- MIT-LICENSE
|
50
|
+
- README
|
51
|
+
- README.rdoc
|
52
|
+
- Rakefile
|
53
|
+
- VERSION
|
54
|
+
- examples/messenger.rb
|
55
|
+
- init.rb
|
56
|
+
- install.rb
|
57
|
+
- lib/m_queue.rb
|
58
|
+
- lib/m_queue/daemon.rb
|
59
|
+
- lib/m_queue/protocols.rb
|
60
|
+
- lib/m_queue/protocols/sparrow.rb
|
61
|
+
- lib/m_queue/protocols/sqs.rb
|
62
|
+
- lib/m_queue/queue.rb
|
63
|
+
- m_queue.gemspec
|
64
|
+
- tasks/m_queue_tasks.rake
|
65
|
+
- test/m_queue_test.rb
|
66
|
+
- test/test_helper.rb
|
67
|
+
- test_mqueue.rb
|
68
|
+
has_rdoc: true
|
69
|
+
homepage: http://github.com/michael/m_queue
|
70
|
+
licenses: []
|
71
|
+
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options:
|
74
|
+
- --charset=UTF-8
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: "0"
|
82
|
+
version:
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: "0"
|
88
|
+
version:
|
89
|
+
requirements: []
|
90
|
+
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 1.3.5
|
93
|
+
signing_key:
|
94
|
+
specification_version: 3
|
95
|
+
summary: MQueue Client Library extracted from Sparrow
|
96
|
+
test_files:
|
97
|
+
- test/m_queue_test.rb
|
98
|
+
- test/test_helper.rb
|
99
|
+
- examples/messenger.rb
|