modern_times 0.3.8 → 0.3.9
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/modern_times/base/supervisor.rb +1 -0
- data/lib/modern_times/jms/request_worker.rb +5 -0
- data/lib/modern_times/manager.rb +37 -21
- data/lib/modern_times/railsable.rb +8 -3
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.9
|
@@ -37,6 +37,7 @@ module ModernTimes
|
|
37
37
|
#tmp_thread.join
|
38
38
|
end
|
39
39
|
worker.thread = Thread.new do
|
40
|
+
java.lang.Thread.current_thread.name = "ModernTimes worker: #{worker}"
|
40
41
|
#ModernTimes.logger.debug "#{worker}: Started thread with priority #{Thread.current.priority}"
|
41
42
|
worker.start
|
42
43
|
end
|
@@ -44,6 +44,7 @@ module ModernTimes
|
|
44
44
|
def perform(object)
|
45
45
|
response = request(object)
|
46
46
|
send_response(@marshal_type, @marshaler, response)
|
47
|
+
post_request(object)
|
47
48
|
rescue Exception => e
|
48
49
|
on_exception(e)
|
49
50
|
end
|
@@ -52,6 +53,10 @@ module ModernTimes
|
|
52
53
|
raise "#{self}: Need to override request method in #{self.class.name} in order to act on #{object}"
|
53
54
|
end
|
54
55
|
|
56
|
+
# Handle any processing that you want to perform after the reply
|
57
|
+
def post_request(object)
|
58
|
+
end
|
59
|
+
|
55
60
|
#########
|
56
61
|
protected
|
57
62
|
#########
|
data/lib/modern_times/manager.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'erb'
|
1
2
|
require 'yaml'
|
2
3
|
require 'socket'
|
3
4
|
|
@@ -6,10 +7,17 @@ module ModernTimes
|
|
6
7
|
attr_accessor :allowed_workers, :dummy_host
|
7
8
|
attr_reader :supervisors
|
8
9
|
|
10
|
+
# Constructs a manager. Accepts a hash of config values
|
11
|
+
# allowed_workers - array of allowed worker classes. For a rails project, this will be set to the
|
12
|
+
# classes located in the app/workers directory which are a kind_of? ModernTimes::Base::Worker
|
13
|
+
# dummy_host - name to use for host as defined by the worker_file. For a rails project, this will be the value of Rails.env
|
14
|
+
# such that a set of workers can be defined for development without having to specify the hostname. For production, a set of
|
15
|
+
# workers could be defined under production or specific workers for each host name
|
9
16
|
def initialize(config={})
|
10
17
|
@stopped = false
|
11
18
|
@config = config
|
12
19
|
@domain = config[:domain] || ModernTimes::DEFAULT_DOMAIN
|
20
|
+
# Unless specifically unconfigured (i.e., Rails.env == test), then enable jmx
|
13
21
|
if config[:jmx] != false
|
14
22
|
@jmx_server = JMX::MBeanServer.new
|
15
23
|
bean = ManagerMBean.new(@domain, self)
|
@@ -21,7 +29,6 @@ module ModernTimes
|
|
21
29
|
self.worker_file = config[:worker_file]
|
22
30
|
@allowed_workers = config[:allowed_workers]
|
23
31
|
stop_on_signal if config[:stop_on_signal]
|
24
|
-
# Unless specifically unconfigured (i.e., Rails.env == test), then enable jmx
|
25
32
|
end
|
26
33
|
|
27
34
|
def add(worker_klass, num_workers, worker_options={})
|
@@ -88,7 +95,7 @@ module ModernTimes
|
|
88
95
|
if File.exist?(file)
|
89
96
|
hash = YAML.load_file(file)
|
90
97
|
hash.each do |worker_name, worker_hash|
|
91
|
-
klass = worker_hash[:klass]
|
98
|
+
klass = worker_hash[:class] || worker_hash[:klass] # Backwards compat, remove klass in next release
|
92
99
|
count = worker_hash[:count]
|
93
100
|
options = worker_hash[:options]
|
94
101
|
options[:name] = worker_name
|
@@ -103,7 +110,7 @@ module ModernTimes
|
|
103
110
|
hash = {}
|
104
111
|
@supervisors.each do |supervisor|
|
105
112
|
hash[supervisor.name] = {
|
106
|
-
:
|
113
|
+
:class => supervisor.worker_klass.name,
|
107
114
|
:count => supervisor.worker_count,
|
108
115
|
:options => supervisor.worker_options
|
109
116
|
}
|
@@ -123,30 +130,39 @@ module ModernTimes
|
|
123
130
|
def worker_file=(file)
|
124
131
|
return unless file
|
125
132
|
@worker_file = file
|
133
|
+
# Don't save new states if the user never dynamically updates the workers
|
134
|
+
# Then they can solely define the workers via this file and updates to the counts won't be ignored.
|
135
|
+
save_persist_file = @persist_file
|
136
|
+
@persist_file = nil unless File.exist?(@persist_file)
|
137
|
+
begin
|
138
|
+
self.class.parse_worker_file(file, @dummy_host) do |klass, count, options|
|
139
|
+
# Don't add if persist_file already created this supervisor
|
140
|
+
add(klass, count, options) unless find_supervisor(options[:name])
|
141
|
+
end
|
142
|
+
ensure
|
143
|
+
@persist_file = save_persist_file
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
# Parse the worker file sending the yield block the class, count and options for each worker.
|
148
|
+
# This is a big kludge to let dummy publishing share this parsing code for Railsable in order to setup dummy workers. Think
|
149
|
+
# about a refactor where the manager knows about dummy publishing mode? Get the previous version to unkludge.
|
150
|
+
def self.parse_worker_file(file, dummy_host, &block)
|
126
151
|
if File.exist?(file)
|
127
|
-
hash = YAML.
|
128
|
-
config =
|
152
|
+
hash = YAML.load(ERB.new(File.read(file)).result(binding))
|
153
|
+
config = dummy_host && hash[dummy_host]
|
129
154
|
unless config
|
130
155
|
host = Socket.gethostname.sub(/\..*/, '')
|
131
156
|
config = hash[host]
|
132
157
|
end
|
133
158
|
return unless config
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
next if find_supervisor(worker_name)
|
142
|
-
klass = worker_hash[:klass] || "#{worker_name}Worker"
|
143
|
-
count = worker_hash[:count]
|
144
|
-
options = worker_hash[:options] || {}
|
145
|
-
options[:name] = worker_name
|
146
|
-
add(klass, count, options)
|
147
|
-
end
|
148
|
-
ensure
|
149
|
-
@persist_file = save_persist_file
|
159
|
+
config.each do |worker_name, worker_hash|
|
160
|
+
klass_name = worker_hash[:class] || worker_hash[:klass] || "#{worker_name}Worker" # Backwards compat, remove :klass in next release
|
161
|
+
klass = Object.const_get(klass_name.to_s)
|
162
|
+
count = worker_hash[:count]
|
163
|
+
options = worker_hash[:options] || {}
|
164
|
+
options[:name] = worker_name
|
165
|
+
yield(klass, count, options)
|
150
166
|
end
|
151
167
|
end
|
152
168
|
end
|
@@ -40,7 +40,14 @@ module ModernTimes
|
|
40
40
|
else
|
41
41
|
Rails.logger.info "Messaging disabled"
|
42
42
|
@is_jms_enabled = false
|
43
|
-
|
43
|
+
worker_file = File.join(Rails.root, "config", "workers.yml")
|
44
|
+
workers = []
|
45
|
+
ModernTimes::Manager.parse_worker_file(worker_file, @env) do |klass, count, options|
|
46
|
+
workers << klass.new(options)
|
47
|
+
end
|
48
|
+
# If no config, then just create a worker for each class in the app/workers directory
|
49
|
+
workers = rails_workers.map {|klass| klass.new({})} if workers.empty?
|
50
|
+
ModernTimes::JMS::Publisher.setup_dummy_publishing(workers)
|
44
51
|
end
|
45
52
|
end
|
46
53
|
|
@@ -69,8 +76,6 @@ module ModernTimes
|
|
69
76
|
end
|
70
77
|
workers
|
71
78
|
end
|
72
|
-
#file = "#{Rails.root}/config/workers.yml"
|
73
|
-
#raise "No worker config file #{file}" unless File.exist?(file)
|
74
79
|
end
|
75
80
|
|
76
81
|
def config
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: modern_times
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.3.
|
5
|
+
version: 0.3.9
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Brad Pardee
|
@@ -11,7 +11,7 @@ autorequire:
|
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
13
|
|
14
|
-
date: 2011-
|
14
|
+
date: 2011-10-14 00:00:00 -04:00
|
15
15
|
default_executable:
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|