reliable-msg-agent 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +90 -0
- data/Rakefile +46 -0
- data/bin/reliable-msg-agent +61 -0
- data/lib/reliable-msg/agent/agent.rb +16 -0
- data/lib/reliable-msg/agent/error.rb +8 -0
- data/lib/reliable-msg/agent/scripts/script_runner.rb +170 -0
- data/lib/reliable-msg/agent/service.rb +44 -0
- data/lib/reliable-msg/agent/version.rb +17 -0
- data/lib/reliable-msg/agent/workers.rb +90 -0
- data/lib/reliable-msg/agent.rb +14 -0
- data/spec/service_spec.rb +36 -0
- data/spec/spec_helper.rb +11 -0
- data/spec/workers_spec.rb +36 -0
- metadata +94 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
|
2
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
3
|
+
a copy of this software and associated documentation files (the
|
4
|
+
"Software"), to deal in the Software without restriction, including
|
5
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
6
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
7
|
+
permit persons to whom the Software is furnished to do so, subject to
|
8
|
+
the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be
|
11
|
+
included in all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
14
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
15
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
16
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
17
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
18
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
19
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
20
|
+
|
data/README.rdoc
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
== Reliable-msg-agent
|
2
|
+
|
3
|
+
reliable-msg-agent is consumer for reliable-msg.
|
4
|
+
|
5
|
+
The pull type approach that acquires the message accumulated
|
6
|
+
in A and processes it is taken.
|
7
|
+
|
8
|
+
|
9
|
+
=== System configuration
|
10
|
+
|
11
|
+
+-------------+
|
12
|
+
| Application |
|
13
|
+
+-------------+
|
14
|
+
|
|
15
|
+
| Push Message
|
16
|
+
+
|
17
|
+
+-------------+
|
18
|
+
| ReliableMsg |+------+
|
19
|
+
+-------------+ |
|
20
|
+
+ | <-- Agent regularly acquires
|
21
|
+
| | the message from ReliableMsg.
|
22
|
+
+ +
|
23
|
+
+-------+ +-------+
|
24
|
+
| Agent | ... + Agent +
|
25
|
+
+-------+ +-------+
|
26
|
+
|
27
|
+
== Getting started
|
28
|
+
|
29
|
+
=== Install
|
30
|
+
|
31
|
+
gem install reliable-msg-agent
|
32
|
+
|
33
|
+
=== Set configuration file
|
34
|
+
|
35
|
+
* {GEM_INSTALL_DIR}/resources/agent.conf
|
36
|
+
please arrange agent.conf in appropriate path.
|
37
|
+
(default: /etc/reliable-msg-agent/agent.conf)
|
38
|
+
* {GEM_INSTALL_DIR}/resources/agent.rb
|
39
|
+
please arrange agent.conf in appropriate path.
|
40
|
+
(default: /etc/reliable-msg-agent/agent.rb)
|
41
|
+
|
42
|
+
== Reliable-msg-agent commands
|
43
|
+
|
44
|
+
$ reliable-msg-agent
|
45
|
+
reliable-msg-agent available commands:
|
46
|
+
stop
|
47
|
+
start
|
48
|
+
|
49
|
+
=== start
|
50
|
+
|
51
|
+
$ reliable-msg-agent start --help
|
52
|
+
Usage: reliable-msg-agent start [options]
|
53
|
+
-v, --verbose Verbose output
|
54
|
+
-c, --conf=CONFFILE Config file
|
55
|
+
-l, --log=LOGFILE Log file
|
56
|
+
-p, --pid=PIDFILE PID file
|
57
|
+
-h, --help Show this message
|
58
|
+
--version Show version
|
59
|
+
|
60
|
+
* -v, --verbose
|
61
|
+
verbose output.
|
62
|
+
* -c, --conf=CONFFILE
|
63
|
+
path for config file. default is /etc/reliable-msg-agent/agent.conf
|
64
|
+
* -l, --log=LOGFILE
|
65
|
+
path for log file. default is /var/reliable-msg-agent/agent.log
|
66
|
+
* -p, --pid=PIDFILE
|
67
|
+
path for pid file. default is /var/reliable-msg-agent/agent.pid
|
68
|
+
* -h, --help
|
69
|
+
show this message.
|
70
|
+
* --version
|
71
|
+
show version.
|
72
|
+
|
73
|
+
=== stop
|
74
|
+
|
75
|
+
$ reliable-msg-agent stop --help
|
76
|
+
Usage: reliable-msg-agent stop [options]
|
77
|
+
-v, --verbose Verbose output
|
78
|
+
-p, --pid=PIDFILE PID file (only for the daemon mode)
|
79
|
+
-h, --help Show this message
|
80
|
+
--version Show version
|
81
|
+
|
82
|
+
* -v, --verbose
|
83
|
+
verbose output.
|
84
|
+
* -p, --pid=PIDFILE
|
85
|
+
path for pid file. default is /var/reliable-msg-agent/agent.pid
|
86
|
+
* -h, --help
|
87
|
+
show this message.
|
88
|
+
* --version
|
89
|
+
show version.
|
90
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
|
2
|
+
require "rubygems"
|
3
|
+
require "rake"
|
4
|
+
require "rake/clean"
|
5
|
+
require "rake/gempackagetask"
|
6
|
+
require "rake/rdoctask"
|
7
|
+
|
8
|
+
$LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
|
9
|
+
require "reliable-msg/agent/version"
|
10
|
+
|
11
|
+
spec = Gem::Specification.new do |s|
|
12
|
+
s.name = "reliable-msg-agent"
|
13
|
+
s.version = ReliableMsg::Agent::Version::STRING
|
14
|
+
s.has_rdoc = true
|
15
|
+
s.extra_rdoc_files = ["README.rdoc"]
|
16
|
+
s.summary = "This(it) is agent daemon for reliable-msg queue"
|
17
|
+
s.description = s.summary
|
18
|
+
s.executables = Dir.glob("bin/**/*").map { |f| File.basename(f) }
|
19
|
+
s.files = %w(History.txt MIT-LICENSE README.rdoc Rakefile) + Dir.glob("{bin,ext,lib,spec}/**/*")
|
20
|
+
s.require_path = "lib"
|
21
|
+
s.bindir = "bin"
|
22
|
+
s.author = "hamajyotan"
|
23
|
+
s.email = "hamajyotan@gmail.com"
|
24
|
+
s.homepage = "https://github.com/hamajyotan/reliable-msg-agent"
|
25
|
+
|
26
|
+
s.add_dependency("reliable-msg")
|
27
|
+
end
|
28
|
+
|
29
|
+
Rake::GemPackageTask.new(spec) do |p|
|
30
|
+
p.gem_spec = spec
|
31
|
+
p.need_tar = true
|
32
|
+
p.need_zip = true
|
33
|
+
end
|
34
|
+
|
35
|
+
Rake::RDocTask.new do |rdoc|
|
36
|
+
files =["README.rdoc", "MIT-LICENSE", "lib/**/*.rb"]
|
37
|
+
rdoc.rdoc_files.add(files)
|
38
|
+
rdoc.main = "README.rdoc" # page to start on
|
39
|
+
rdoc.title = "reliable-msg-agent Docs"
|
40
|
+
rdoc.rdoc_dir = "doc/rdoc" # rdoc output folder
|
41
|
+
rdoc.options << "--line-numbers"
|
42
|
+
end
|
43
|
+
|
44
|
+
Dir["tasks/**/*.rake"].each { |t| load t }
|
45
|
+
task :default => [:spec]
|
46
|
+
|
@@ -0,0 +1,61 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "optparse"
|
4
|
+
|
5
|
+
require "rubygems"
|
6
|
+
require "reliable-msg/agent"
|
7
|
+
|
8
|
+
parsers = {}
|
9
|
+
options = {}
|
10
|
+
|
11
|
+
parsers["start"] = OptionParser.new { |parser|
|
12
|
+
parser.program_name += " start"
|
13
|
+
|
14
|
+
parser.on("-v", "--verbose", "Verbose output") {
|
15
|
+
options[:verbose] = true
|
16
|
+
}
|
17
|
+
parser.on("-c", "--conf=CONFFILE", "Config file") { |v|
|
18
|
+
options[:conf] = v
|
19
|
+
}
|
20
|
+
parser.on("-l", "--log=LOGFILE", "Log file") { |v|
|
21
|
+
options[:log] = v
|
22
|
+
}
|
23
|
+
parser.on("-p", "--pid=PIDFILE", "PID file") { |v|
|
24
|
+
options[:pid] = v
|
25
|
+
}
|
26
|
+
}
|
27
|
+
parsers["stop"] = OptionParser.new { |parser|
|
28
|
+
parser.program_name += " stop"
|
29
|
+
|
30
|
+
parser.on("-v", "--verbose", "Verbose output") {
|
31
|
+
options[:verbose] = true
|
32
|
+
}
|
33
|
+
parser.on("-p", "--pid=PIDFILE", "PID file (only for the daemon mode)") { |v|
|
34
|
+
options[:pid] = v
|
35
|
+
}
|
36
|
+
}
|
37
|
+
parsers.each { |k,v| parser = v
|
38
|
+
parser.version = ReliableMsg::Agent::Version::STRING
|
39
|
+
|
40
|
+
parser.on_tail("-h", "--help", "Show this message") {
|
41
|
+
$stderr.puts parser
|
42
|
+
exit
|
43
|
+
}
|
44
|
+
parser.on_tail("--version", "Show version") {
|
45
|
+
$stdout.puts ReliableMsg::Agent::Version::STRING
|
46
|
+
exit
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
subcommand = ARGV.shift
|
51
|
+
unless parsers.keys.include?(subcommand)
|
52
|
+
$stderr.puts "#{File.basename($0, ".*")} available commands:"
|
53
|
+
$stderr.puts parsers.keys.map { |cmd| "\t#{cmd}" }.join("\n")
|
54
|
+
$stderr.puts
|
55
|
+
exit 1
|
56
|
+
end
|
57
|
+
parsers[subcommand].parse! ARGV
|
58
|
+
|
59
|
+
require "reliable-msg/agent/scripts/script_runner"
|
60
|
+
ReliableMsg::Agent::ScriptRunner.new.send subcommand.to_sym, options
|
61
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
|
2
|
+
require "rubygems"
|
3
|
+
require "reliable-msg/agent"
|
4
|
+
|
5
|
+
module ReliableMsg::Agent #:nodoc:
|
6
|
+
class Agent
|
7
|
+
def initialize logger
|
8
|
+
@logger = logger
|
9
|
+
end
|
10
|
+
|
11
|
+
def call msg, options = {}
|
12
|
+
raise AgentError, "#call(msg,options={}) not implemented!"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
@@ -0,0 +1,170 @@
|
|
1
|
+
|
2
|
+
require "rubygems"
|
3
|
+
require "reliable-msg/agent"
|
4
|
+
|
5
|
+
require "erb"
|
6
|
+
require "logger"
|
7
|
+
require "yaml"
|
8
|
+
require "fileutils"
|
9
|
+
require "timeout"
|
10
|
+
require "etc"
|
11
|
+
|
12
|
+
module ReliableMsg::Agent #:nodoc:
|
13
|
+
class ScriptRunner #:nodoc:
|
14
|
+
|
15
|
+
def start options = {}
|
16
|
+
$stderr.puts "*** Starting ReliableMsg-Agent..."
|
17
|
+
|
18
|
+
default_options = {
|
19
|
+
:verbose => false,
|
20
|
+
:conf => "/etc/reliable-msg-agent/agent.conf",
|
21
|
+
:log => "/var/reliable-msg-agent/agent.log",
|
22
|
+
:pid => "/var/reliable-msg-agent/agent.pid",
|
23
|
+
}
|
24
|
+
opt = default_options.merge options
|
25
|
+
|
26
|
+
conf = load_configurations opt[:conf]
|
27
|
+
change_privilege conf
|
28
|
+
pidfile_accessible_test opt[:pid]
|
29
|
+
logger = create_logger conf["logger"], opt[:log]
|
30
|
+
|
31
|
+
agent_definition conf["agent"]
|
32
|
+
|
33
|
+
daemonize(logger) {
|
34
|
+
service = Service.new logger, conf
|
35
|
+
|
36
|
+
register_signal_handler logger, service, opt[:pid]
|
37
|
+
|
38
|
+
service.start
|
39
|
+
write_pidfile opt[:pid]
|
40
|
+
while service.alive?; sleep 3; end
|
41
|
+
}
|
42
|
+
|
43
|
+
rescue Exception => e
|
44
|
+
$stderr.puts "--- ReliableMsg-Agent error! - #{e.message}"
|
45
|
+
$stderr.puts e.backtrace.join("\n\t") if opt[:verbose]
|
46
|
+
exit 1
|
47
|
+
|
48
|
+
ensure
|
49
|
+
$stderr.puts "*** done."
|
50
|
+
end
|
51
|
+
|
52
|
+
def stop options = {}
|
53
|
+
$stderr.puts "*** Stopping ReliableMsg-Agent..."
|
54
|
+
|
55
|
+
default_options = {
|
56
|
+
:verbose => false,
|
57
|
+
:pid => "/var/reliable-msg-agent/agent.pid",
|
58
|
+
}
|
59
|
+
opt = default_options.merge options
|
60
|
+
|
61
|
+
# send signal
|
62
|
+
pid = File.open(opt[:pid], "r") { |f| f.read }.to_i
|
63
|
+
Process.kill :TERM, pid
|
64
|
+
|
65
|
+
# wait
|
66
|
+
timeout(10.0) { Process.waitpid pid rescue nil }
|
67
|
+
|
68
|
+
rescue Exception => e
|
69
|
+
$stderr.puts "--- ReliableMsg-Agent error! - #{e.message}"
|
70
|
+
$stderr.puts e.backtrace.join("\n\t") if opt[:verbose]
|
71
|
+
exit 1
|
72
|
+
|
73
|
+
ensure
|
74
|
+
$stderr.puts "*** done."
|
75
|
+
end
|
76
|
+
|
77
|
+
private
|
78
|
+
|
79
|
+
def load_configurations conffile
|
80
|
+
YAML.load(ERB.new(IO.read(conffile)).result)
|
81
|
+
end
|
82
|
+
|
83
|
+
def change_privilege conf
|
84
|
+
user = conf["user"]
|
85
|
+
uid = begin
|
86
|
+
Etc.getpwnam(user.to_s).uid
|
87
|
+
rescue ArgumentError
|
88
|
+
raise "can't find user for #{user}"
|
89
|
+
end
|
90
|
+
group = conf["group"]
|
91
|
+
gid = begin
|
92
|
+
Etc.getgrnam(group.to_s).gid
|
93
|
+
rescue ArgumentError
|
94
|
+
raise "can't find group for #{group}"
|
95
|
+
end
|
96
|
+
|
97
|
+
raise "Dont't run as root user." if uid == 0
|
98
|
+
|
99
|
+
Process::Sys.setegid(gid)
|
100
|
+
Process::Sys.seteuid(uid)
|
101
|
+
end
|
102
|
+
|
103
|
+
def pidfile_accessible_test pid
|
104
|
+
raise "PID file already exists - #{pid}" if File.exist?(pid)
|
105
|
+
FileUtils.touch pid; File.unlink pid
|
106
|
+
end
|
107
|
+
|
108
|
+
def create_logger creation_procedure, logfile
|
109
|
+
if creation_procedure
|
110
|
+
eval(creation_procedure.to_s).call(logfile)
|
111
|
+
else
|
112
|
+
Logger.new(logfile)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def daemonize logger
|
117
|
+
fork {
|
118
|
+
Process.setsid
|
119
|
+
fork {
|
120
|
+
begin
|
121
|
+
Dir.chdir("/")
|
122
|
+
$stdin.reopen "/dev/null", "r"
|
123
|
+
$stdout.reopen "/dev/null", "a"
|
124
|
+
$stderr.reopen "/dev/null", "a"
|
125
|
+
|
126
|
+
yield
|
127
|
+
sleep
|
128
|
+
|
129
|
+
rescue Exception => e
|
130
|
+
logger.fatal { "ReliableMsg-Agent error! - #{e.message}" }
|
131
|
+
logger.fatal { e.backtrace.join("\n\t") }
|
132
|
+
exit! 1
|
133
|
+
end
|
134
|
+
}
|
135
|
+
}
|
136
|
+
end
|
137
|
+
|
138
|
+
def register_signal_handler logger, service, pidfile
|
139
|
+
stopping = false
|
140
|
+
[:TERM].each { |sig|
|
141
|
+
Signal.trap(sig) {
|
142
|
+
unless stopping
|
143
|
+
begin
|
144
|
+
stopping = true
|
145
|
+
service.stop
|
146
|
+
File.unlink pidfile if File.exist? pidfile
|
147
|
+
exit! 0
|
148
|
+
|
149
|
+
rescue Exception => e
|
150
|
+
File.unlink pidfile if File.exist? pidfile
|
151
|
+
logger.fatal { "ReliableMsg-Agent error! - #{e.message}" }
|
152
|
+
logger.fatal { e.backtrace.join("\n\t") }
|
153
|
+
exit! 1
|
154
|
+
end
|
155
|
+
end
|
156
|
+
}
|
157
|
+
}
|
158
|
+
end
|
159
|
+
|
160
|
+
def write_pidfile pidfile
|
161
|
+
File.open(pidfile, "w") { |f| f.puts $$ }
|
162
|
+
end
|
163
|
+
|
164
|
+
def agent_definition deffile
|
165
|
+
Agent.class_eval open(deffile, "r") { |f| f.read }
|
166
|
+
end
|
167
|
+
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
@@ -0,0 +1,44 @@
|
|
1
|
+
|
2
|
+
require "rubygems"
|
3
|
+
require "reliable-msg/agent"
|
4
|
+
|
5
|
+
require "monitor"
|
6
|
+
|
7
|
+
module ReliableMsg::Agent #:nodoc:
|
8
|
+
class Service
|
9
|
+
def initialize logger, options = {}
|
10
|
+
@logger = logger
|
11
|
+
@options = options
|
12
|
+
|
13
|
+
@workers = Workers.new @logger, @options
|
14
|
+
@locker = Monitor.new
|
15
|
+
end
|
16
|
+
|
17
|
+
def start
|
18
|
+
@locker.synchronize {
|
19
|
+
raise AgentError, "service already started." if alive?
|
20
|
+
|
21
|
+
@logger.info { "reliable-msg agent service starting..." }
|
22
|
+
@workers.start
|
23
|
+
@logger.info { "reliable-msg agent service started." }
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
def stop
|
28
|
+
@locker.synchronize {
|
29
|
+
raise AgentError, "service already stopped." unless alive?
|
30
|
+
|
31
|
+
@logger.info { "reliable-msg agent service stopping..." }
|
32
|
+
@workers.stop
|
33
|
+
@logger.info { "reliable-msg agent service stopped." }
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
def alive?
|
38
|
+
@locker.synchronize {
|
39
|
+
!! @workers.alive?
|
40
|
+
}
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
|
2
|
+
require "rubygems"
|
3
|
+
require "reliable-msg/agent"
|
4
|
+
|
5
|
+
module ReliableMsg::Agent #:nodoc:
|
6
|
+
module Version #:nodoc:
|
7
|
+
unless defined? MAJOR
|
8
|
+
MAJOR = 0
|
9
|
+
MINOR = 0
|
10
|
+
TINY = 1
|
11
|
+
PRE = nil
|
12
|
+
|
13
|
+
STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
@@ -0,0 +1,90 @@
|
|
1
|
+
|
2
|
+
require "rubygems"
|
3
|
+
require "reliable-msg/agent"
|
4
|
+
|
5
|
+
require "monitor"
|
6
|
+
|
7
|
+
module ReliableMsg::Agent #:nodoc:
|
8
|
+
class Workers
|
9
|
+
|
10
|
+
@@default_options = {
|
11
|
+
:uri => "druby://localhost:6438",
|
12
|
+
:every => 1.0,
|
13
|
+
:target => "queue.*",
|
14
|
+
:threads => 1,
|
15
|
+
}.freeze
|
16
|
+
|
17
|
+
def initialize logger, options = {}
|
18
|
+
@logger = logger
|
19
|
+
@options = options
|
20
|
+
@locker = Monitor.new
|
21
|
+
@threads = nil
|
22
|
+
end
|
23
|
+
|
24
|
+
def start
|
25
|
+
@locker.synchronize {
|
26
|
+
raise AgentError, "workers already started." if alive?
|
27
|
+
|
28
|
+
@logger.info { "starting workers." }
|
29
|
+
|
30
|
+
threads = (t = @options[:threads].to_i) <= 0 ? 1 : t
|
31
|
+
@threads = (1..threads).inject([]) { |t, i|
|
32
|
+
t << Thread.fork { worker_loop }
|
33
|
+
}
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
def stop
|
38
|
+
@locker.synchronize {
|
39
|
+
raise AgentError, "workers already stopped." unless alive?
|
40
|
+
|
41
|
+
@logger.info { "stopping workers." }
|
42
|
+
|
43
|
+
@threads.each { |t| t[:dying] = true }
|
44
|
+
@threads.each { |t| t.wakeup rescue nil }
|
45
|
+
@threads.each { |t| t.join }
|
46
|
+
@threads = nil
|
47
|
+
}
|
48
|
+
end
|
49
|
+
|
50
|
+
def alive?
|
51
|
+
@locker.synchronize { !! @threads }
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
|
56
|
+
def worker_loop
|
57
|
+
agent = Agent.new @logger
|
58
|
+
uri = @options[:uri] || @@default_options[:uri]
|
59
|
+
every = @options[:every] || @@default_options[:every]
|
60
|
+
target = @options[:target] || @@default_options[:target]
|
61
|
+
|
62
|
+
until Thread.current[:dying]
|
63
|
+
begin
|
64
|
+
sleep every
|
65
|
+
|
66
|
+
remote_qm = DRb::DRbObject.new_with_uri uri
|
67
|
+
queue_name = remote_qm.stale_queue target
|
68
|
+
next unless queue_name
|
69
|
+
|
70
|
+
q = ReliableMsg::Queue.new queue_name, :drb_uri => uri
|
71
|
+
q.get { |m|
|
72
|
+
begin
|
73
|
+
tx = Thread.current[ReliableMsg::Client::THREAD_CURRENT_TX]
|
74
|
+
Thread.current[ReliableMsg::Client::THREAD_CURRENT_TX] = nil
|
75
|
+
|
76
|
+
@logger.info { "message received - <#{m.id}>" }
|
77
|
+
raise AgentError, "agent proc failed." unless agent.call(m.dup)
|
78
|
+
ensure
|
79
|
+
Thread.current[ReliableMsg::Client::THREAD_CURRENT_TX] = tx
|
80
|
+
end
|
81
|
+
}
|
82
|
+
rescue Exception => e
|
83
|
+
@logger.warn { "error in fetch-msg/agent-proc: #{e}\n#{e.backtrace.join("\n\t")}" }
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
@@ -0,0 +1,14 @@
|
|
1
|
+
|
2
|
+
require "rubygems"
|
3
|
+
require "reliable-msg"
|
4
|
+
|
5
|
+
module ReliableMsg #:nodoc:
|
6
|
+
module Agent #:nodoc:
|
7
|
+
autoload :Version , "reliable-msg/agent/version"
|
8
|
+
autoload :AgentError, "reliable-msg/agent/error"
|
9
|
+
autoload :Service , "reliable-msg/agent/service"
|
10
|
+
autoload :Workers , "reliable-msg/agent/workers"
|
11
|
+
autoload :Agent , "reliable-msg/agent/agent"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
@@ -0,0 +1,36 @@
|
|
1
|
+
|
2
|
+
require File.dirname(__FILE__) + "/spec_helper.rb"
|
3
|
+
|
4
|
+
require "logger"
|
5
|
+
|
6
|
+
describe ReliableMsg::Agent::Service do
|
7
|
+
before do
|
8
|
+
l = Logger.new(nil)
|
9
|
+
@s = ReliableMsg::Agent::Service.new l
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should be able to #start" do
|
13
|
+
@s.start
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should not be alive" do
|
17
|
+
@s.alive?.should_not be_true
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "When started" do
|
21
|
+
before do
|
22
|
+
@s.start
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should be alive" do
|
26
|
+
@s.alive?.should be_true
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
after do
|
32
|
+
@s.stop rescue nil
|
33
|
+
@s = nil
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
|
2
|
+
require File.dirname(__FILE__) + "/spec_helper.rb"
|
3
|
+
|
4
|
+
require "logger"
|
5
|
+
|
6
|
+
describe ReliableMsg::Agent::Workers do
|
7
|
+
before do
|
8
|
+
l = Logger.new(nil)
|
9
|
+
@w = ReliableMsg::Agent::Workers.new l
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should be able to #start" do
|
13
|
+
@w.start
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should not be alive" do
|
17
|
+
@w.alive?.should_not be_true
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "When started" do
|
21
|
+
before do
|
22
|
+
@w.start
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should be alive" do
|
26
|
+
@w.alive?.should be_true
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
after do
|
32
|
+
@w.stop rescue nil
|
33
|
+
@w = nil
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: reliable-msg-agent
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- hamajyotan
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-03-18 00:00:00 +09:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: reliable-msg
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
description: This(it) is agent daemon for reliable-msg queue
|
36
|
+
email: hamajyotan@gmail.com
|
37
|
+
executables:
|
38
|
+
- reliable-msg-agent
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- README.rdoc
|
43
|
+
files:
|
44
|
+
- History.txt
|
45
|
+
- MIT-LICENSE
|
46
|
+
- README.rdoc
|
47
|
+
- Rakefile
|
48
|
+
- bin/reliable-msg-agent
|
49
|
+
- lib/reliable-msg/agent/error.rb
|
50
|
+
- lib/reliable-msg/agent/workers.rb
|
51
|
+
- lib/reliable-msg/agent/version.rb
|
52
|
+
- lib/reliable-msg/agent/service.rb
|
53
|
+
- lib/reliable-msg/agent/agent.rb
|
54
|
+
- lib/reliable-msg/agent/scripts/script_runner.rb
|
55
|
+
- lib/reliable-msg/agent.rb
|
56
|
+
- spec/spec_helper.rb
|
57
|
+
- spec/service_spec.rb
|
58
|
+
- spec/workers_spec.rb
|
59
|
+
has_rdoc: true
|
60
|
+
homepage: https://github.com/hamajyotan/reliable-msg-agent
|
61
|
+
licenses: []
|
62
|
+
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
hash: 3
|
74
|
+
segments:
|
75
|
+
- 0
|
76
|
+
version: "0"
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
hash: 3
|
83
|
+
segments:
|
84
|
+
- 0
|
85
|
+
version: "0"
|
86
|
+
requirements: []
|
87
|
+
|
88
|
+
rubyforge_project:
|
89
|
+
rubygems_version: 1.3.7
|
90
|
+
signing_key:
|
91
|
+
specification_version: 3
|
92
|
+
summary: This(it) is agent daemon for reliable-msg queue
|
93
|
+
test_files: []
|
94
|
+
|