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.
Files changed (63) hide show
  1. data/CHANGELOG +103 -0
  2. data/COPYING +348 -0
  3. data/README.rdoc +64 -0
  4. data/Rakefile +131 -0
  5. data/bin/hq +6 -0
  6. data/config/boot.rb +224 -0
  7. data/config/databases/frontbase.yml +28 -0
  8. data/config/databases/mysql.yml +54 -0
  9. data/config/databases/oracle.yml +39 -0
  10. data/config/databases/postgresql.yml +48 -0
  11. data/config/databases/sqlite2.yml +16 -0
  12. data/config/databases/sqlite3.yml +19 -0
  13. data/config/environment.rb +20 -0
  14. data/config/environments/development.cfg +35 -0
  15. data/config/environments/production.cfg +35 -0
  16. data/config/environments/test.cfg +35 -0
  17. data/config/generators/job/templates/job.rb.erb +20 -0
  18. data/config/generators/message/templates/messages/MESSAGE.proto.erb +12 -0
  19. data/config/generators/model/templates/models/MODEL.rb.erb +3 -0
  20. data/config/generators/service/templates/services/SERVICE.rb.erb +43 -0
  21. data/config/homeq.cfg +35 -0
  22. data/extras/consumer.rb +85 -0
  23. data/extras/homeq.cfg +49 -0
  24. data/extras/hqd.rb +33 -0
  25. data/extras/producer.rb +79 -0
  26. data/extras/simple_consumer.rb +53 -0
  27. data/lib/homeq/base/base.rb +44 -0
  28. data/lib/homeq/base/commando.rb +81 -0
  29. data/lib/homeq/base/config.rb +99 -0
  30. data/lib/homeq/base/exception.rb +48 -0
  31. data/lib/homeq/base/histogram.rb +141 -0
  32. data/lib/homeq/base/logger.rb +185 -0
  33. data/lib/homeq/base/ohash.rb +297 -0
  34. data/lib/homeq/base/options.rb +171 -0
  35. data/lib/homeq/base/poolable.rb +100 -0
  36. data/lib/homeq/base/system.rb +446 -0
  37. data/lib/homeq/cli.rb +35 -0
  38. data/lib/homeq/cp/commands.rb +71 -0
  39. data/lib/homeq/cp/connection.rb +97 -0
  40. data/lib/homeq/cp/cp.rb +30 -0
  41. data/lib/homeq/cp/server.rb +105 -0
  42. data/lib/homeq/sobs/client.rb +119 -0
  43. data/lib/homeq/sobs/connection.rb +635 -0
  44. data/lib/homeq/sobs/foreman.rb +237 -0
  45. data/lib/homeq/sobs/job.rb +66 -0
  46. data/lib/homeq/sobs/message.rb +49 -0
  47. data/lib/homeq/sobs/queue.rb +224 -0
  48. data/lib/homeq/sobs/sender.rb +150 -0
  49. data/lib/homeq/sobs/server.rb +654 -0
  50. data/lib/homeq/sobs/sobs.rb +45 -0
  51. data/lib/homeq/sobs/topology.rb +111 -0
  52. data/lib/homeq.rb +106 -0
  53. data/lib/tasks/Rakefile +49 -0
  54. data/lib/tasks/database.rake +387 -0
  55. data/lib/tasks/gem.rake +9 -0
  56. data/lib/tasks/generate.rake +192 -0
  57. data/lib/tasks/hq.rake +171 -0
  58. data/lib/tasks/testing.rake +95 -0
  59. data/lib/tasks/utility.rb +17 -0
  60. data/script/console.rb +45 -0
  61. data/script/generate +7 -0
  62. data/test/unittest.rb +51 -0
  63. metadata +222 -0
@@ -0,0 +1,85 @@
1
+ #!/usr/bin/ruby
2
+ #############################################################################
3
+ #
4
+ # $Id: sobsd.rb 4 2008-08-26 15:59:44Z colin $
5
+ #
6
+ # Author:: Colin Steele (colin@colinsteele.org)
7
+ # Homepage::
8
+ #
9
+ # TODO: info
10
+ #
11
+ #----------------------------------------------------------------------------
12
+ #
13
+ # Copyright (C) 2008 by Colin Steele. All Rights Reserved.
14
+ # colin@colinsteele.org
15
+ #
16
+ # This program is free software; you can redistribute it and/or modify
17
+ # it under the terms of either: 1) the GNU General Public License
18
+ # as published by the Free Software Foundation; either version 2 of the
19
+ # License, or (at your option) any later version; or 2) Ruby's License.
20
+ #
21
+ # See the file COPYING for complete licensing information.
22
+ #
23
+ #---------------------------------------------------------------------------
24
+ #
25
+ #
26
+ #############################################################################
27
+
28
+ require 'rubygems'
29
+ require 'homeq'
30
+
31
+ # Gives us easy access to log, system and config.
32
+ include HomeQ
33
+
34
+ # This is a client's main way of interfacing with HomeQ - the JOB
35
+
36
+ class MyJob < HomeQ::SOBS::Job
37
+ include HomeQ
38
+ @jobs = 0
39
+ @start_at = nil
40
+ @end_at = nil
41
+ class << self
42
+ attr :jobs, true
43
+ attr :start_at, true
44
+ attr :end_at, true
45
+ end
46
+ def initialize(message, queue)
47
+ super(message, queue)
48
+ MyJob.jobs += 1
49
+ end
50
+ def run
51
+ super
52
+ if (MyJob.jobs % 1000) == 1
53
+ if MyJob.jobs != 1
54
+ MyJob.end_at = Time.now
55
+ logger.info {
56
+ "TIME ##{MyJob.jobs}: #{MyJob.end_at - MyJob.start_at}"
57
+ }
58
+ end
59
+ MyJob.start_at = Time.now
60
+ end
61
+ if MyJob.jobs == options.number_of_messages
62
+ MyJob.end_at = Time.now
63
+ logger.info {
64
+ "TIME: #{MyJob.end_at - MyJob.start_at}"
65
+ }
66
+ sys.stop
67
+ end
68
+ end
69
+ end
70
+
71
+ # A demonstration of how to add app-specific option parsing to HomeQ
72
+
73
+ parser = HomeQ::Base::Options::Options.instance.parser
74
+ options = HomeQ::Base::Options::Options.instance.options
75
+ options.number_of_messages = 100
76
+ parser.separator ""
77
+ parser.separator "CONSUMER SPECIFIC options:"
78
+ parser.on("-n", "--messages N", "Consume this many messages") { |n|
79
+ options.number_of_messages = n.to_i
80
+ }
81
+
82
+ config.queue_name('consumer')
83
+ sys.handlers['server'] = MyJob
84
+ sys.config_file = 'homeq.cfg'
85
+ sys.start
data/extras/homeq.cfg ADDED
@@ -0,0 +1,49 @@
1
+
2
+ ######
3
+ # BASIC CONFIGURATION
4
+ ######
5
+
6
+ if !queue_name
7
+ raise "No queue name is set for this process"
8
+ end
9
+ queue_retry 10 # client queue connections retried after this long
10
+
11
+ ######
12
+ # CONTROL PORTS
13
+ ######
14
+
15
+ # Since all of this runs on localhost, need different control ports
16
+
17
+ case queue_name
18
+ when 'server'
19
+ cp_port 49000
20
+ when 'producer'
21
+ cp_port 49001
22
+ when 'consumer'
23
+ cp_port 49002
24
+ end
25
+
26
+ ######
27
+ # LOGGING
28
+ ######
29
+
30
+ log_id queue_name # makes things more readable
31
+ log_level 'INFO' # overridden by command line "-vv"'s
32
+
33
+ ######
34
+ # QUEUE CONNECTION GRAPH
35
+ ######
36
+
37
+ topology {
38
+ queue('server') {
39
+ located_at('localhost', 50000)
40
+ }
41
+ queue('consumer') {
42
+ located_at('localhost', 50001)
43
+ reads_from('server')
44
+ }
45
+ queue('producer') {
46
+ located_at('localhost', 50002)
47
+ writes_to('server')
48
+ }
49
+ }
data/extras/hqd.rb ADDED
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/ruby
2
+ #############################################################################
3
+ #
4
+ # $Id: sobsd.rb 4 2008-08-26 15:59:44Z colin $
5
+ #
6
+ # Author:: Colin Steele (colin@colinsteele.org)
7
+ # Homepage::
8
+ #
9
+ # TODO: info
10
+ #
11
+ #----------------------------------------------------------------------------
12
+ #
13
+ # Copyright (C) 2008 by Colin Steele. All Rights Reserved.
14
+ # colin@colinsteele.org
15
+ #
16
+ # This program is free software; you can redistribute it and/or modify
17
+ # it under the terms of either: 1) the GNU General Public License
18
+ # as published by the Free Software Foundation; either version 2 of the
19
+ # License, or (at your option) any later version; or 2) Ruby's License.
20
+ #
21
+ # See the file COPYING for complete licensing information.
22
+ #
23
+ #---------------------------------------------------------------------------
24
+ #
25
+ #
26
+ #############################################################################
27
+
28
+ require 'rubygems'
29
+ require 'homeq'
30
+
31
+ include HomeQ
32
+ sys.config_file = 'homeq.cfg'
33
+ sys.start
@@ -0,0 +1,79 @@
1
+ #!/usr/bin/ruby
2
+ #############################################################################
3
+ #
4
+ # $Id: sobsd.rb 4 2008-08-26 15:59:44Z colin $
5
+ #
6
+ # Author:: Colin Steele (colin@colinsteele.org)
7
+ # Homepage::
8
+ #
9
+ # TODO: info
10
+ #
11
+ #----------------------------------------------------------------------------
12
+ #
13
+ # Copyright (C) 2008 by Colin Steele. All Rights Reserved.
14
+ # colin@colinsteele.org
15
+ #
16
+ # This program is free software; you can redistribute it and/or modify
17
+ # it under the terms of either: 1) the GNU General Public License
18
+ # as published by the Free Software Foundation; either version 2 of the
19
+ # License, or (at your option) any later version; or 2) Ruby's License.
20
+ #
21
+ # See the file COPYING for complete licensing information.
22
+ #
23
+ #---------------------------------------------------------------------------
24
+ #
25
+ #
26
+ #############################################################################
27
+
28
+ require 'rubygems'
29
+ require 'homeq'
30
+
31
+ # Gives us easy access to log, system and config.
32
+ include HomeQ
33
+
34
+ # A demonstration of how to add app-specific option parsing to HomeQ
35
+
36
+ parser = HomeQ::Base::Options::Options.instance.parser
37
+ options = HomeQ::Base::Options::Options.instance.options
38
+ options.number_of_messages = 100
39
+ parser.separator ""
40
+ parser.separator "PRODUCER SPECIFIC options:"
41
+ parser.on("-n", "--messages N", "Produce this many messages") { |n|
42
+ options.number_of_messages = n.to_i
43
+ }
44
+
45
+ config.queue_name('producer')
46
+ sys.config_file = 'homeq.cfg'
47
+ start_time = Time.now
48
+
49
+ def send_batch(options, sent_so_far)
50
+ limit = options.number_of_messages
51
+ data = "This is a small payload"
52
+ i = 0
53
+ loop do
54
+ return if sent_so_far > limit
55
+ sent_ok = HomeQ::SOBS::Queue.send('server', data, sent_so_far) { |app_data|
56
+ puts "*#{app_data}" if ((app_data.to_i % 100) == 0)
57
+ if app_data.to_i >= limit
58
+ sys.stop
59
+ end
60
+ }
61
+ break unless sent_ok
62
+ sent_so_far += 1
63
+ break if i > 10
64
+ i += 1
65
+ p sent_so_far if ((sent_so_far % 100) == 0)
66
+ end
67
+ EventMachine::next_tick {
68
+ send_batch(options, sent_so_far)
69
+ }
70
+ end
71
+
72
+ sys.start {
73
+ EventMachine::next_tick {
74
+ send_batch(options, 1)
75
+ }
76
+ }
77
+
78
+ end_time = Time.now
79
+ puts "TIME: #{end_time - start_time}"
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/ruby
2
+ #############################################################################
3
+ #
4
+ # $Id: sobsd.rb 4 2008-08-26 15:59:44Z colin $
5
+ #
6
+ # Author:: Colin Steele (colin@colinsteele.org)
7
+ # Homepage::
8
+ #
9
+ # TODO: info
10
+ #
11
+ #----------------------------------------------------------------------------
12
+ #
13
+ # Copyright (C) 2008 by Colin Steele. All Rights Reserved.
14
+ # colin@colinsteele.org
15
+ #
16
+ # This program is free software; you can redistribute it and/or modify
17
+ # it under the terms of either: 1) the GNU General Public License
18
+ # as published by the Free Software Foundation; either version 2 of the
19
+ # License, or (at your option) any later version; or 2) Ruby's License.
20
+ #
21
+ # See the file COPYING for complete licensing information.
22
+ #
23
+ #---------------------------------------------------------------------------
24
+ #
25
+ #
26
+ #############################################################################
27
+
28
+ require 'rubygems'
29
+ require 'homeq'
30
+
31
+ # Gives us easy access to log, system and config.
32
+ include HomeQ
33
+
34
+ # This is a client's main way of interfacing with HomeQ - the JOB
35
+ class MyJob < HomeQ::SOBS::Job
36
+ # This method is called when a job has been received and needs to be
37
+ # worked on.
38
+ def run
39
+ super
40
+ puts payload
41
+ end
42
+ end
43
+
44
+ # This tells the system who we are - what queue this process owns
45
+ config.queue_name('consumer')
46
+
47
+ # Install our handler for jobs we get from the "server" queue
48
+ sys.handlers['server'] = MyJob
49
+
50
+ # The config file is found here. This can also be specified with -c FILE
51
+ # on the command line.
52
+ sys.config_file = 'homeq.cfg'
53
+ sys.start
@@ -0,0 +1,44 @@
1
+ #############################################################################
2
+ #
3
+ # $Id: base.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
+ module HomeQ
28
+ module HQ
29
+ def hq
30
+ HomeQ::Base::System.instance
31
+ end
32
+ alias_method :sys, :hq
33
+ end
34
+ end
35
+
36
+ require 'homeq/base/histogram'
37
+ require 'homeq/base/ohash'
38
+ require 'homeq/base/poolable'
39
+ require 'homeq/base/commando'
40
+ require 'homeq/base/exception'
41
+ require 'homeq/base/config'
42
+ require 'homeq/base/options'
43
+ require 'homeq/base/logger'
44
+ require 'homeq/base/system'
@@ -0,0 +1,81 @@
1
+ #############################################################################
2
+ #
3
+ # $Id: config.rb 8 2008-08-27 20:15:22Z 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 'singleton'
28
+
29
+ module HomeQ
30
+
31
+ module Base
32
+
33
+ module Commando
34
+
35
+ module ClassMethods
36
+ def document_command(name, help)
37
+ CommandScheme.instance.command_list[name.to_s] = help
38
+ end
39
+ def config_accessor(sym, help=nil)
40
+ class_eval %{
41
+ document_command("#{sym} [x]", help || "Get/set #{sym}")
42
+ def #{sym}=(*val)
43
+ #{sym}(*val)
44
+ end
45
+ def #{sym}(*val)
46
+ cfg = HomeQ::Base::Configuration::Configuration.instance
47
+ if val.empty?
48
+ cfg.instance_eval("@#{sym}")
49
+ else
50
+ cfg.instance_eval("@#{sym} = val.size == 1 ? val[0] : val")
51
+ end
52
+ end
53
+ }
54
+ end
55
+ end # module ClassMethods
56
+
57
+ module InstanceMethods
58
+ extend ClassMethods
59
+ def show_commands
60
+ str = ''
61
+ CommandScheme.instance.command_list.keys.sort.each {|name|
62
+ help = CommandScheme.instance.command_list[name]
63
+ str << "#{'%-24s' % name}: #{help}\n"
64
+ }
65
+ str
66
+ end
67
+ end
68
+
69
+ class CommandScheme
70
+ include Singleton
71
+ attr :command_list, true
72
+ def initialize
73
+ @command_list = {}
74
+ end
75
+ end
76
+
77
+ end # module Commando
78
+
79
+ end # module Base
80
+
81
+ end # module HomeQ
@@ -0,0 +1,99 @@
1
+ #############################################################################
2
+ #
3
+ # $Id: config.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
+ require 'singleton'
28
+ require 'forwardable'
29
+
30
+ module HomeQ
31
+
32
+ module Base
33
+
34
+ module Configuration
35
+
36
+ class Configuration
37
+
38
+ include Singleton
39
+ include HQ
40
+ include Commando::InstanceMethods
41
+
42
+ extend Forwardable
43
+
44
+ attr :gems, false
45
+
46
+ def initialize
47
+ @hash = {}
48
+ @gems = []
49
+ end
50
+
51
+ # support some general Array methods
52
+ def_delegators :@hash, :[], :[]=
53
+
54
+ # support anything of the form config.foo = bar
55
+ def method_missing(meth, args)
56
+ if meth.to_s.match(/(.*)=$/)
57
+ @hash[$1] = args
58
+ end
59
+ end
60
+
61
+ def gem(name, opts = {})
62
+ @gems << [name, opts]
63
+ end
64
+
65
+ def config
66
+ self
67
+ end
68
+
69
+ def evaluate_config(lines)
70
+ # Reload commando methods, as they may have changed.
71
+ self.class.class_eval {
72
+ include Commando::InstanceMethods
73
+ }
74
+ eval(lines)
75
+ end
76
+
77
+ def read_config_file(path)
78
+ hq.die("Nil config file path") unless path
79
+ File.open(path) { |f|
80
+ begin
81
+ evaluate_config(f.read)
82
+ rescue => e
83
+ e.message << " Config file: #{path}"
84
+ raise
85
+ end
86
+ }
87
+ end
88
+
89
+ end # class Configuration
90
+
91
+ def config
92
+ @config ||= Configuration.instance
93
+ end
94
+
95
+ end # module Configuration
96
+
97
+ end # module Base
98
+
99
+ end # module HomeQ
@@ -0,0 +1,48 @@
1
+ #############################################################################
2
+ #
3
+ # $Id: exception.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 Base
30
+
31
+ class ConfigurationError < Exception
32
+ end
33
+
34
+ class ServerError < Exception
35
+ end
36
+
37
+ class UnknownQueue < Exception
38
+ end
39
+
40
+ class ReadOnlyQueue < Exception
41
+ end
42
+
43
+ class ConnectionClosed < Exception
44
+ end
45
+
46
+ end
47
+
48
+ end