homeq 1.1.4
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/CHANGELOG +103 -0
- data/COPYING +348 -0
- data/README.rdoc +64 -0
- data/Rakefile +131 -0
- data/bin/hq +6 -0
- data/config/boot.rb +224 -0
- data/config/databases/frontbase.yml +28 -0
- data/config/databases/mysql.yml +54 -0
- data/config/databases/oracle.yml +39 -0
- data/config/databases/postgresql.yml +48 -0
- data/config/databases/sqlite2.yml +16 -0
- data/config/databases/sqlite3.yml +19 -0
- data/config/environment.rb +20 -0
- data/config/environments/development.cfg +35 -0
- data/config/environments/production.cfg +35 -0
- data/config/environments/test.cfg +35 -0
- data/config/generators/job/templates/job.rb.erb +20 -0
- data/config/generators/message/templates/messages/MESSAGE.proto.erb +12 -0
- data/config/generators/model/templates/models/MODEL.rb.erb +3 -0
- data/config/generators/service/templates/services/SERVICE.rb.erb +43 -0
- data/config/homeq.cfg +35 -0
- data/extras/consumer.rb +85 -0
- data/extras/homeq.cfg +49 -0
- data/extras/hqd.rb +33 -0
- data/extras/producer.rb +79 -0
- data/extras/simple_consumer.rb +53 -0
- data/lib/homeq/base/base.rb +44 -0
- data/lib/homeq/base/commando.rb +81 -0
- data/lib/homeq/base/config.rb +99 -0
- data/lib/homeq/base/exception.rb +48 -0
- data/lib/homeq/base/histogram.rb +141 -0
- data/lib/homeq/base/logger.rb +185 -0
- data/lib/homeq/base/ohash.rb +297 -0
- data/lib/homeq/base/options.rb +171 -0
- data/lib/homeq/base/poolable.rb +100 -0
- data/lib/homeq/base/system.rb +446 -0
- data/lib/homeq/cli.rb +35 -0
- data/lib/homeq/cp/commands.rb +71 -0
- data/lib/homeq/cp/connection.rb +97 -0
- data/lib/homeq/cp/cp.rb +30 -0
- data/lib/homeq/cp/server.rb +105 -0
- data/lib/homeq/sobs/client.rb +119 -0
- data/lib/homeq/sobs/connection.rb +635 -0
- data/lib/homeq/sobs/foreman.rb +237 -0
- data/lib/homeq/sobs/job.rb +66 -0
- data/lib/homeq/sobs/message.rb +49 -0
- data/lib/homeq/sobs/queue.rb +224 -0
- data/lib/homeq/sobs/sender.rb +150 -0
- data/lib/homeq/sobs/server.rb +654 -0
- data/lib/homeq/sobs/sobs.rb +45 -0
- data/lib/homeq/sobs/topology.rb +111 -0
- data/lib/homeq.rb +106 -0
- data/lib/tasks/Rakefile +49 -0
- data/lib/tasks/database.rake +387 -0
- data/lib/tasks/gem.rake +9 -0
- data/lib/tasks/generate.rake +192 -0
- data/lib/tasks/hq.rake +171 -0
- data/lib/tasks/testing.rake +95 -0
- data/lib/tasks/utility.rb +17 -0
- data/script/console.rb +45 -0
- data/script/generate +7 -0
- data/test/unittest.rb +51 -0
- metadata +222 -0
data/lib/homeq/cli.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
#############################################################################
|
2
|
+
#
|
3
|
+
# $Id: homeq.rb 38 2008-10-21 02:38:26Z colin $
|
4
|
+
#
|
5
|
+
# Author:: Colin Steele (colin@colinsteele.org)
|
6
|
+
# Homepage::
|
7
|
+
#
|
8
|
+
#----------------------------------------------------------------------------
|
9
|
+
#
|
10
|
+
# Copyright (C) 2008 by Colin Steele. All Rights Reserved.
|
11
|
+
# colin@colinsteele.org
|
12
|
+
#
|
13
|
+
# This program is free software; you can redistribute it and/or modify
|
14
|
+
# it under the terms of either: 1) the GNU General Public License
|
15
|
+
# as published by the Free Software Foundation; either version 2 of the
|
16
|
+
# License, or (at your option) any later version; or 2) Ruby's License.
|
17
|
+
#
|
18
|
+
# See the file COPYING for complete licensing information.
|
19
|
+
#
|
20
|
+
#---------------------------------------------------------------------------
|
21
|
+
#
|
22
|
+
#
|
23
|
+
#############################################################################
|
24
|
+
|
25
|
+
module HomeQ
|
26
|
+
module CLI
|
27
|
+
def self.execute(dest_dir, rakefile)
|
28
|
+
args = ARGV.dup
|
29
|
+
args += ["-I", "#{HOMEQ_ROOT}/lib/tasks"]
|
30
|
+
args += ["-f", rakefile]
|
31
|
+
ENV['HOMEQ_CLI_DEST'] = dest_dir
|
32
|
+
exec('rake', *args)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
#############################################################################
|
2
|
+
#
|
3
|
+
# $Id: commands.rb 48 2008-11-19 05:11:59Z colin $
|
4
|
+
#
|
5
|
+
# Author:: Colin Steele (colin@colinsteele.org)
|
6
|
+
# Homepage::
|
7
|
+
#
|
8
|
+
# TODO: info
|
9
|
+
#
|
10
|
+
#----------------------------------------------------------------------------
|
11
|
+
#
|
12
|
+
# Copyright (C) 2008 by Colin Steele. All Rights Reserved.
|
13
|
+
# colin@colinsteele.org
|
14
|
+
#
|
15
|
+
# This program is free software; you can redistribute it and/or modify
|
16
|
+
# it under the terms of either: 1) the GNU General Public License
|
17
|
+
# as published by the Free Software Foundation; either version 2 of the
|
18
|
+
# License, or (at your option) any later version; or 2) Ruby's License.
|
19
|
+
#
|
20
|
+
# See the file COPYING for complete licensing information.
|
21
|
+
#
|
22
|
+
#---------------------------------------------------------------------------
|
23
|
+
#
|
24
|
+
#
|
25
|
+
#############################################################################
|
26
|
+
|
27
|
+
module HomeQ
|
28
|
+
|
29
|
+
module CP
|
30
|
+
|
31
|
+
module Commands
|
32
|
+
|
33
|
+
def shutdown(*args)
|
34
|
+
if !args || !args.include?('really')
|
35
|
+
return "Really??"
|
36
|
+
end
|
37
|
+
logger.info {
|
38
|
+
"Shutdown initiated by control port."
|
39
|
+
}
|
40
|
+
EventMachine::add_timer(3) do
|
41
|
+
HomeQ::Base::System.instance.stop
|
42
|
+
end
|
43
|
+
EventMachine::add_timer(1) do
|
44
|
+
close
|
45
|
+
end
|
46
|
+
"OK"
|
47
|
+
end
|
48
|
+
|
49
|
+
def close
|
50
|
+
close_connection
|
51
|
+
end
|
52
|
+
|
53
|
+
alias :quit :close
|
54
|
+
alias :exit :close
|
55
|
+
|
56
|
+
def help
|
57
|
+
show_commands
|
58
|
+
end
|
59
|
+
|
60
|
+
end # Commands
|
61
|
+
|
62
|
+
end # CP
|
63
|
+
|
64
|
+
end # HomeQ
|
65
|
+
|
66
|
+
module HomeQ::Base::Commando::InstanceMethods
|
67
|
+
include HomeQ::CP::Commands
|
68
|
+
document_command "help", "A little love"
|
69
|
+
document_command "quit|exit|close", "Close control port connection"
|
70
|
+
document_command "shutdown", "Shut down this homeq process"
|
71
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
#############################################################################
|
2
|
+
#
|
3
|
+
# $Id: connection.rb 40 2008-10-23 14:20:06Z colin $
|
4
|
+
#
|
5
|
+
# Author:: Colin Steele (colin@colinsteele.org)
|
6
|
+
# Homepage::
|
7
|
+
#
|
8
|
+
# TODO: info
|
9
|
+
#
|
10
|
+
#----------------------------------------------------------------------------
|
11
|
+
#
|
12
|
+
# Copyright (C) 2008 by Colin Steele. All Rights Reserved.
|
13
|
+
# colin@colinsteele.org
|
14
|
+
#
|
15
|
+
# This program is free software; you can redistribute it and/or modify
|
16
|
+
# it under the terms of either: 1) the GNU General Public License
|
17
|
+
# as published by the Free Software Foundation; either version 2 of the
|
18
|
+
# License, or (at your option) any later version; or 2) Ruby's License.
|
19
|
+
#
|
20
|
+
# See the file COPYING for complete licensing information.
|
21
|
+
#
|
22
|
+
#---------------------------------------------------------------------------
|
23
|
+
#
|
24
|
+
#
|
25
|
+
#############################################################################
|
26
|
+
|
27
|
+
module HomeQ
|
28
|
+
|
29
|
+
module CP
|
30
|
+
|
31
|
+
include Base::Logging
|
32
|
+
|
33
|
+
class Connection < EventMachine::Connection
|
34
|
+
|
35
|
+
include HomeQ
|
36
|
+
|
37
|
+
TRACE_REXP = /^#{Regexp.escape(__FILE__)}/
|
38
|
+
|
39
|
+
attr :server, true
|
40
|
+
|
41
|
+
def receive_data data
|
42
|
+
if (data == "\004" || # ^D
|
43
|
+
data == "\377\364\377\375\006") # ^C
|
44
|
+
close_connection
|
45
|
+
return
|
46
|
+
end
|
47
|
+
|
48
|
+
begin
|
49
|
+
send_data("#{eval(data)}\r\n")
|
50
|
+
rescue SyntaxError, StandardError, Exception
|
51
|
+
trace = []
|
52
|
+
stack = $!.backtrace
|
53
|
+
trace << stack.pop until stack.first =~ TRACE_REXP
|
54
|
+
send_data([$!, $!.message, trace].join("\n\t"))
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
def unbind
|
60
|
+
server.connections.delete(self) if server
|
61
|
+
logger.info {
|
62
|
+
"Connection has terminated to control port client " +
|
63
|
+
"#{@peer[1]}:#{@peer[0]}."
|
64
|
+
}
|
65
|
+
end
|
66
|
+
|
67
|
+
def post_init
|
68
|
+
@peer = Socket.unpack_sockaddr_in(get_peername)
|
69
|
+
logger.info {
|
70
|
+
"Control port connection received from " +
|
71
|
+
"#{@peer[1]}:#{@peer[0]}."
|
72
|
+
}
|
73
|
+
|
74
|
+
send_data issue
|
75
|
+
|
76
|
+
# Add all the commands as methods
|
77
|
+
self.class.class_eval {
|
78
|
+
include HomeQ::Base::Commando::InstanceMethods
|
79
|
+
}
|
80
|
+
end
|
81
|
+
|
82
|
+
protected
|
83
|
+
|
84
|
+
def issue
|
85
|
+
str = "\r\n"
|
86
|
+
str << "\r\n" + $0.center(79)
|
87
|
+
str << "\r\n" + "Queue: #{config.queue_name}".center(79)
|
88
|
+
str << "This is a live ruby interpreter.".center(79) + "\r\n"
|
89
|
+
str << "Careful, you can seriously mess this process up.".center(79)
|
90
|
+
str << "\r\n\r\n"
|
91
|
+
end
|
92
|
+
|
93
|
+
end # Connection
|
94
|
+
|
95
|
+
end # CP
|
96
|
+
|
97
|
+
end # HomeQ
|
data/lib/homeq/cp/cp.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
#############################################################################
|
2
|
+
#
|
3
|
+
# $Id: cp.rb 42 2008-10-24 05:53:35Z colin $
|
4
|
+
#
|
5
|
+
# Author:: Colin Steele (colin@colinsteele.org)
|
6
|
+
# Homepage::
|
7
|
+
#
|
8
|
+
# TODO: info
|
9
|
+
#
|
10
|
+
#----------------------------------------------------------------------------
|
11
|
+
#
|
12
|
+
# Copyright (C) 2008 by Colin Steele. All Rights Reserved.
|
13
|
+
# colin@colinsteele.org
|
14
|
+
#
|
15
|
+
# This program is free software; you can redistribute it and/or modify
|
16
|
+
# it under the terms of either: 1) the GNU General Public License
|
17
|
+
# as published by the Free Software Foundation; either version 2 of the
|
18
|
+
# License, or (at your option) any later version; or 2) Ruby's License.
|
19
|
+
#
|
20
|
+
# See the file COPYING for complete licensing information.
|
21
|
+
#
|
22
|
+
#---------------------------------------------------------------------------
|
23
|
+
#
|
24
|
+
#
|
25
|
+
#############################################################################
|
26
|
+
|
27
|
+
require 'homeq/cp/commands'
|
28
|
+
require 'homeq/cp/connection'
|
29
|
+
require 'homeq/cp/server'
|
30
|
+
|
@@ -0,0 +1,105 @@
|
|
1
|
+
#############################################################################
|
2
|
+
#
|
3
|
+
# $Id: server.rb 40 2008-10-23 14:20:06Z colin $
|
4
|
+
#
|
5
|
+
# Author:: Colin Steele (colin@colinsteele.org)
|
6
|
+
# Homepage::
|
7
|
+
#
|
8
|
+
# TODO: info
|
9
|
+
#
|
10
|
+
#----------------------------------------------------------------------------
|
11
|
+
#
|
12
|
+
# Copyright (C) 2008 by Colin Steele. All Rights Reserved.
|
13
|
+
# colin@colinsteele.org
|
14
|
+
#
|
15
|
+
# This program is free software; you can redistribute it and/or modify
|
16
|
+
# it under the terms of either: 1) the GNU General Public License
|
17
|
+
# as published by the Free Software Foundation; either version 2 of the
|
18
|
+
# License, or (at your option) any later version; or 2) Ruby's License.
|
19
|
+
#
|
20
|
+
# See the file COPYING for complete licensing information.
|
21
|
+
#
|
22
|
+
#---------------------------------------------------------------------------
|
23
|
+
#
|
24
|
+
#
|
25
|
+
#############################################################################
|
26
|
+
|
27
|
+
module HomeQ
|
28
|
+
|
29
|
+
module CP
|
30
|
+
|
31
|
+
class Server
|
32
|
+
|
33
|
+
DEFAULT_PORT = 56001
|
34
|
+
DEFAULT_HOST = 'localhost'
|
35
|
+
|
36
|
+
include Base::Logging
|
37
|
+
include Base::Configuration
|
38
|
+
|
39
|
+
attr_accessor :connections
|
40
|
+
|
41
|
+
# Make our config info available
|
42
|
+
module HomeQ::Base::Commando::InstanceMethods
|
43
|
+
config_accessor :cp_host
|
44
|
+
config_accessor :cp_port
|
45
|
+
end
|
46
|
+
|
47
|
+
def initialize(host=nil, port=nil)
|
48
|
+
@host = host || DEFAULT_HOST
|
49
|
+
@port = port || DEFAULT_PORT
|
50
|
+
@connections = []
|
51
|
+
end
|
52
|
+
|
53
|
+
def start
|
54
|
+
begin
|
55
|
+
@signature = EventMachine.start_server(@host,
|
56
|
+
@port,
|
57
|
+
CP::Connection) { |conn|
|
58
|
+
conn.server = self
|
59
|
+
}
|
60
|
+
rescue Exception => e
|
61
|
+
msg = "Error starting CP listener #{@host}:#{@port}. " +
|
62
|
+
"Likely it's a config error. " +
|
63
|
+
"Original error: #{e.message}"
|
64
|
+
Base::System.instance.die(msg)
|
65
|
+
else
|
66
|
+
logger.info {
|
67
|
+
"Control port running on #{@host}:#{@port}"
|
68
|
+
}
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def stop
|
73
|
+
EventMachine.stop_server(@signature)
|
74
|
+
unless wait_for_connections
|
75
|
+
# Still some running
|
76
|
+
EventMachine.add_periodic_timer(1) {
|
77
|
+
logger.info {
|
78
|
+
'.'
|
79
|
+
}
|
80
|
+
wait_for_connections
|
81
|
+
}
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
protected
|
86
|
+
|
87
|
+
def wait_for_connections
|
88
|
+
if @connections.empty?
|
89
|
+
true
|
90
|
+
else
|
91
|
+
logger.info {
|
92
|
+
"Waiting for #{@connections.length} connections to finish."
|
93
|
+
}
|
94
|
+
@connections.each { |c|
|
95
|
+
c.close_connection_after_writing
|
96
|
+
}
|
97
|
+
false
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
end # Server
|
102
|
+
|
103
|
+
end # CP
|
104
|
+
|
105
|
+
end # HomeQ
|
@@ -0,0 +1,119 @@
|
|
1
|
+
#############################################################################
|
2
|
+
#
|
3
|
+
# $Id: client.rb 40 2008-10-23 14:20:06Z colin $
|
4
|
+
#
|
5
|
+
# Author:: Colin Steele (colin@colinsteele.org)
|
6
|
+
# Homepage::
|
7
|
+
#
|
8
|
+
# TODO: info
|
9
|
+
#
|
10
|
+
#----------------------------------------------------------------------------
|
11
|
+
#
|
12
|
+
# Copyright (C) 2008 by Colin Steele. All Rights Reserved.
|
13
|
+
# colin@colinsteele.org
|
14
|
+
#
|
15
|
+
# This program is free software; you can redistribute it and/or modify
|
16
|
+
# it under the terms of either: 1) the GNU General Public License
|
17
|
+
# as published by the Free Software Foundation; either version 2 of the
|
18
|
+
# License, or (at your option) any later version; or 2) Ruby's License.
|
19
|
+
#
|
20
|
+
# See the file COPYING for complete licensing information.
|
21
|
+
#
|
22
|
+
#---------------------------------------------------------------------------
|
23
|
+
#
|
24
|
+
#
|
25
|
+
#############################################################################
|
26
|
+
|
27
|
+
module HomeQ
|
28
|
+
|
29
|
+
module SOBS
|
30
|
+
|
31
|
+
class Client < SOBS::Connection
|
32
|
+
|
33
|
+
attr :queue, true # the queue that owns this connection
|
34
|
+
attr :host, true
|
35
|
+
attr :port, true
|
36
|
+
attr :retry, true
|
37
|
+
|
38
|
+
def self.connect(host, port, interval, server, queue)
|
39
|
+
EventMachine::connect(host,
|
40
|
+
port,
|
41
|
+
self) { |conn|
|
42
|
+
conn.host = host
|
43
|
+
conn.port = port
|
44
|
+
conn.retry = interval
|
45
|
+
conn.server = server
|
46
|
+
conn.queue = queue
|
47
|
+
}
|
48
|
+
end
|
49
|
+
|
50
|
+
def initialize
|
51
|
+
super
|
52
|
+
@host = @port = @retry = nil
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
######################################################################
|
57
|
+
# SOBS::Connection entry points
|
58
|
+
######################################################################
|
59
|
+
|
60
|
+
def opened
|
61
|
+
@queue.opened(self) if @queue
|
62
|
+
subscribe if readable?
|
63
|
+
end
|
64
|
+
|
65
|
+
def closed
|
66
|
+
@queue.closed if @queue
|
67
|
+
retry_connection_after_interval(@retry)
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
######################################################################
|
72
|
+
# High level message interface - receiving
|
73
|
+
######################################################################
|
74
|
+
|
75
|
+
def receive_reserved(message)
|
76
|
+
@queue.create_job(message)
|
77
|
+
end
|
78
|
+
|
79
|
+
def receive_inserted(message)
|
80
|
+
@queue.ack(message)
|
81
|
+
end
|
82
|
+
|
83
|
+
def receive_deleted(message)
|
84
|
+
@queue.deleted(message)
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
######################################################################
|
89
|
+
# Other
|
90
|
+
######################################################################
|
91
|
+
|
92
|
+
def readable?
|
93
|
+
@queue.readable?
|
94
|
+
end
|
95
|
+
|
96
|
+
def writeable?
|
97
|
+
@queue.writeable?
|
98
|
+
end
|
99
|
+
|
100
|
+
protected
|
101
|
+
|
102
|
+
def get_next_message
|
103
|
+
reserve if readable?
|
104
|
+
end
|
105
|
+
|
106
|
+
def retry_connection_after_interval(interval)
|
107
|
+
EventMachine::add_timer(interval) do
|
108
|
+
logger.info {
|
109
|
+
"Trying connection to #{host}:#{port}."
|
110
|
+
}
|
111
|
+
Client.connect(@host, @port, @retry, @server, @queue)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
end # Client
|
116
|
+
|
117
|
+
end # module SOBS
|
118
|
+
|
119
|
+
end # module HomeQ
|