skynet 0.9.2 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +49 -0
- data/Manifest.txt +84 -6
- data/README.txt +75 -64
- data/app_generators/skynet_install/skynet_install_generator.rb +14 -8
- data/app_generators/skynet_install/templates/migration.rb +1 -24
- data/app_generators/skynet_install/templates/skynet_config.rb +50 -0
- data/app_generators/skynet_install/templates/skynet_initializer.rb +1 -0
- data/app_generators/skynet_install/templates/{skynet_schema.sql → skynet_mysql_schema.sql} +1 -24
- data/bin/skynet +37 -10
- data/bin/skynet_install +5 -5
- data/bin/skynet_tuplespace_server +27 -19
- data/examples/dgrep/README +70 -0
- data/examples/dgrep/config/skynet_config.rb +26 -0
- data/examples/dgrep/data/shakespeare/README +2 -0
- data/examples/dgrep/data/shakespeare/poetry/loverscomplaint +381 -0
- data/examples/dgrep/data/shakespeare/poetry/rapeoflucrece +2199 -0
- data/examples/dgrep/data/shakespeare/poetry/sonnets +2633 -0
- data/examples/dgrep/data/shakespeare/poetry/various +640 -0
- data/examples/dgrep/data/shakespeare/poetry/venusandadonis +1423 -0
- data/examples/dgrep/data/testfile1.txt +1 -0
- data/examples/dgrep/data/testfile2.txt +1 -0
- data/examples/dgrep/data/testfile3.txt +1 -0
- data/examples/dgrep/data/testfile4.txt +1 -0
- data/examples/dgrep/lib/dgrep.rb +59 -0
- data/examples/dgrep/lib/mapreduce_test.rb +32 -0
- data/examples/dgrep/lib/most_common_words.rb +45 -0
- data/examples/dgrep/script/dgrep +75 -0
- data/examples/rails_mysql_example/README +66 -0
- data/examples/rails_mysql_example/Rakefile +10 -0
- data/examples/rails_mysql_example/app/controllers/application.rb +10 -0
- data/examples/rails_mysql_example/app/helpers/application_helper.rb +3 -0
- data/examples/rails_mysql_example/app/models/user.rb +21 -0
- data/examples/rails_mysql_example/app/models/user_favorite.rb +5 -0
- data/examples/rails_mysql_example/app/models/user_mailer.rb +12 -0
- data/examples/rails_mysql_example/app/views/user_mailer/welcome.erb +5 -0
- data/examples/rails_mysql_example/config/boot.rb +109 -0
- data/examples/rails_mysql_example/config/database.yml +42 -0
- data/examples/rails_mysql_example/config/environment.rb +59 -0
- data/examples/rails_mysql_example/config/environments/development.rb +18 -0
- data/examples/rails_mysql_example/config/environments/production.rb +19 -0
- data/examples/rails_mysql_example/config/environments/test.rb +22 -0
- data/examples/rails_mysql_example/config/initializers/inflections.rb +10 -0
- data/examples/rails_mysql_example/config/initializers/mime_types.rb +5 -0
- data/examples/rails_mysql_example/config/initializers/skynet.rb +1 -0
- data/examples/rails_mysql_example/config/routes.rb +35 -0
- data/examples/rails_mysql_example/config/skynet_config.rb +36 -0
- data/examples/rails_mysql_example/db/migrate/001_create_skynet_tables.rb +43 -0
- data/examples/rails_mysql_example/db/migrate/002_create_users.rb +16 -0
- data/examples/rails_mysql_example/db/migrate/003_create_user_favorites.rb +14 -0
- data/examples/rails_mysql_example/db/schema.rb +85 -0
- data/examples/rails_mysql_example/db/skynet_mysql_schema.sql +33 -0
- data/examples/rails_mysql_example/doc/README_FOR_APP +2 -0
- data/examples/rails_mysql_example/lib/tasks/rails_mysql_example.rake +20 -0
- data/examples/rails_mysql_example/public/.htaccess +40 -0
- data/examples/rails_mysql_example/public/404.html +30 -0
- data/examples/rails_mysql_example/public/422.html +30 -0
- data/examples/rails_mysql_example/public/500.html +30 -0
- data/examples/rails_mysql_example/public/dispatch.cgi +10 -0
- data/examples/rails_mysql_example/public/dispatch.fcgi +24 -0
- data/examples/rails_mysql_example/public/dispatch.rb +10 -0
- data/{log/debug.log → examples/rails_mysql_example/public/favicon.ico} +0 -0
- data/examples/rails_mysql_example/public/images/rails.png +0 -0
- data/examples/rails_mysql_example/public/index.html +277 -0
- data/examples/rails_mysql_example/public/javascripts/application.js +2 -0
- data/examples/rails_mysql_example/public/javascripts/controls.js +963 -0
- data/examples/rails_mysql_example/public/javascripts/dragdrop.js +972 -0
- data/examples/rails_mysql_example/public/javascripts/effects.js +1120 -0
- data/examples/rails_mysql_example/public/javascripts/prototype.js +4225 -0
- data/examples/rails_mysql_example/public/robots.txt +5 -0
- data/examples/rails_mysql_example/script/about +3 -0
- data/examples/rails_mysql_example/script/console +3 -0
- data/examples/rails_mysql_example/script/destroy +3 -0
- data/examples/rails_mysql_example/script/generate +3 -0
- data/examples/rails_mysql_example/script/performance/benchmarker +3 -0
- data/examples/rails_mysql_example/script/performance/profiler +3 -0
- data/examples/rails_mysql_example/script/performance/request +3 -0
- data/examples/rails_mysql_example/script/plugin +3 -0
- data/examples/rails_mysql_example/script/process/inspector +3 -0
- data/examples/rails_mysql_example/script/process/reaper +3 -0
- data/examples/rails_mysql_example/script/process/spawner +3 -0
- data/examples/rails_mysql_example/script/runner +3 -0
- data/examples/rails_mysql_example/script/server +3 -0
- data/examples/rails_mysql_example/test/fixtures/user_favorites.yml +9 -0
- data/examples/rails_mysql_example/test/fixtures/users.yml +11 -0
- data/examples/rails_mysql_example/test/test_helper.rb +38 -0
- data/examples/rails_mysql_example/test/unit/user_favorite_test.rb +8 -0
- data/examples/rails_mysql_example/test/unit/user_test.rb +8 -0
- data/extras/README +7 -0
- data/extras/init.d/skynet +87 -0
- data/extras/nagios/check_skynet.sh +121 -0
- data/extras/rails/controllers/skynet_controller.rb +43 -0
- data/extras/rails/views/skynet/index.rhtml +137 -0
- data/lib/skynet.rb +59 -1
- data/lib/skynet/mapreduce_helper.rb +2 -2
- data/lib/skynet/mapreduce_test.rb +32 -1
- data/lib/skynet/message_queue_adapters/mysql.rb +422 -539
- data/lib/skynet/message_queue_adapters/tuple_space.rb +45 -71
- data/lib/skynet/skynet_active_record_extensions.rb +22 -11
- data/lib/skynet/skynet_config.rb +54 -20
- data/lib/skynet/skynet_console.rb +4 -1
- data/lib/skynet/skynet_console_helper.rb +5 -1
- data/lib/skynet/skynet_debugger.rb +58 -4
- data/lib/skynet/skynet_job.rb +61 -24
- data/lib/skynet/skynet_launcher.rb +29 -3
- data/lib/skynet/skynet_logger.rb +11 -1
- data/lib/skynet/skynet_manager.rb +403 -240
- data/lib/skynet/skynet_message.rb +1 -3
- data/lib/skynet/skynet_message_queue.rb +42 -19
- data/lib/skynet/skynet_partitioners.rb +19 -15
- data/lib/skynet/skynet_ruby_extensions.rb +18 -0
- data/lib/skynet/skynet_tuplespace_server.rb +17 -14
- data/lib/skynet/skynet_worker.rb +132 -98
- data/lib/skynet/version.rb +1 -1
- data/script/destroy +0 -0
- data/script/generate +0 -0
- data/script/txt2html +0 -0
- data/test/test_helper.rb +2 -0
- data/test/test_skynet.rb +13 -5
- data/test/test_skynet_manager.rb +24 -9
- data/test/test_skynet_task.rb +1 -1
- data/website/index.html +77 -29
- data/website/index.txt +53 -24
- data/website/stylesheets/screen.css +12 -12
- metadata +156 -66
- data/app_generators/skynet_install/templates/skynet +0 -46
- data/log/skynet.log +0 -29
- data/log/skynet_tuplespace_server.log +0 -7
- data/log/skynet_worker.pid +0 -1
@@ -10,17 +10,17 @@ end
|
|
10
10
|
class Skynet
|
11
11
|
class Error < StandardError
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
class RequestExpiredError < Skynet::Error
|
15
15
|
end
|
16
|
-
|
16
|
+
|
17
17
|
class InvalidMessage < Skynet::Error
|
18
18
|
end
|
19
19
|
|
20
20
|
class MessageQueueAdapter
|
21
|
-
|
21
|
+
|
22
22
|
class TupleSpace < Skynet::MessageQueueAdapter
|
23
|
-
|
23
|
+
|
24
24
|
include SkynetDebugger
|
25
25
|
|
26
26
|
USE_FALLBACK_TASKS = true
|
@@ -36,11 +36,11 @@ class Skynet
|
|
36
36
|
:tuplespace
|
37
37
|
end
|
38
38
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
@ts =
|
39
|
+
attr_accessor :start_options
|
40
|
+
|
41
|
+
def initialize(options={})
|
42
|
+
@start_options = options
|
43
|
+
@ts = self.class.get_tuple_space(options)
|
44
44
|
end
|
45
45
|
|
46
46
|
def take_next_task(curver,timeout=nil,payload_type=nil,queue_id=0)
|
@@ -72,36 +72,6 @@ class Skynet
|
|
72
72
|
take_fallback_message(message)
|
73
73
|
end
|
74
74
|
|
75
|
-
|
76
|
-
def write_worker_status(task, timeout=nil)
|
77
|
-
begin
|
78
|
-
take_worker_status(task,0.00001)
|
79
|
-
rescue Skynet::RequestExpiredError
|
80
|
-
end
|
81
|
-
write(Skynet::WorkerStatusMessage.new(task), timeout)
|
82
|
-
end
|
83
|
-
|
84
|
-
def take_worker_status(task, timeout=nil)
|
85
|
-
Skynet::WorkerStatusMessage.new(take(Skynet::WorkerStatusMessage.worker_status_template(task), timeout))
|
86
|
-
end
|
87
|
-
|
88
|
-
def read_all_worker_statuses(hostname=nil)
|
89
|
-
ws = Skynet::WorkerStatusMessage.all_workers_template(hostname)
|
90
|
-
workers = read_all(ws).collect{ |w| Skynet::WorkerStatusMessage.new(w) }#.sort{ |a,b| a.process_id <=> b.process_id }
|
91
|
-
end
|
92
|
-
|
93
|
-
def clear_worker_status(hostname=nil)
|
94
|
-
cnt = 0
|
95
|
-
begin
|
96
|
-
loop do
|
97
|
-
take(Skynet::WorkerStatusMessage.new([:status, :worker, hostname, nil, nil]),0.01)
|
98
|
-
cnt += 1
|
99
|
-
end
|
100
|
-
rescue Skynet::RequestExpiredError
|
101
|
-
end
|
102
|
-
cnt
|
103
|
-
end
|
104
|
-
|
105
75
|
def list_tasks(iteration=nil,queue_id=0)
|
106
76
|
read_all(Skynet::Message.outstanding_tasks_template(iteration,queue_id))
|
107
77
|
end
|
@@ -165,20 +135,20 @@ class Skynet
|
|
165
135
|
rescue DRb::DRbConnError, Errno::ECONNREFUSED => e
|
166
136
|
error "ERROR #{e.inspect}", caller
|
167
137
|
end
|
168
|
-
|
138
|
+
|
169
139
|
tasks.size.times do |ii|
|
170
140
|
take(Skynet::Message.outstanding_tasks_template,0.00001)
|
171
141
|
end
|
172
|
-
|
142
|
+
|
173
143
|
results = read_all(Skynet::Message.outstanding_results_template)
|
174
144
|
results.size.times do |ii|
|
175
145
|
take(Skynet::Message.outstanding_results_template,0.00001)
|
176
146
|
end
|
177
|
-
|
147
|
+
|
178
148
|
task_tuples = read_all(Skynet::Message.outstanding_tasks_template)
|
179
149
|
result_tuples = read_all(Skynet::Message.outstanding_results_template)
|
180
150
|
return task_tuples + result_tuples
|
181
|
-
end
|
151
|
+
end
|
182
152
|
|
183
153
|
def stats
|
184
154
|
t1 = Time.now
|
@@ -188,7 +158,7 @@ class Skynet
|
|
188
158
|
p_tasks = tasks.partition {|task| task[9] == 0}
|
189
159
|
{:taken_tasks => p_tasks[1].size, :untaken_tasks => p_tasks[0].size, :results => list_results.size, :time => t2.to_f}
|
190
160
|
end
|
191
|
-
|
161
|
+
|
192
162
|
private
|
193
163
|
|
194
164
|
attr_accessor :ts
|
@@ -208,7 +178,7 @@ class Skynet
|
|
208
178
|
def read_all(template)
|
209
179
|
ts_command(:read_all,template)
|
210
180
|
end
|
211
|
-
|
181
|
+
|
212
182
|
###### FALLBACK METHODS
|
213
183
|
def write_fallback_task(message)
|
214
184
|
return unless USE_FALLBACK_TASKS
|
@@ -243,25 +213,25 @@ class Skynet
|
|
243
213
|
else
|
244
214
|
raise InvalidMessage.new("You must provide a valid Skynet::Message object when calling #{command}. You passed #{message.inspect}.")
|
245
215
|
end
|
246
|
-
|
216
|
+
|
247
217
|
begin
|
248
218
|
if command==:read_all
|
249
219
|
return ts.send(command,tuple)
|
250
220
|
else
|
251
221
|
return ts.send(command,tuple,timeout)
|
252
222
|
end
|
253
|
-
|
223
|
+
|
254
224
|
rescue Rinda::RequestExpiredError
|
255
225
|
raise Skynet::RequestExpiredError.new
|
256
226
|
rescue DRb::DRbConnError => e
|
257
227
|
begin
|
258
|
-
|
259
|
-
@ts = self.class.get_tuple_space
|
260
|
-
raise Skynet::ConnectionError.new("Can't find ring finger. #{e.inspect}")
|
228
|
+
error "Couldnt run command [#{command}] on tuplespace. start options: #{@start_options.inspect}"
|
229
|
+
@ts = self.class.get_tuple_space(@start_options)
|
230
|
+
raise Skynet::ConnectionError.new("Can't find ring finger. #{e.inspect} #{@start_options.inspect}")
|
261
231
|
# tries += 1
|
262
232
|
# next
|
263
233
|
rescue Skynet::ConnectionError => e
|
264
|
-
raise Skynet::ConnectionError.new("Can't find ring finger. #{e.inspect}")
|
234
|
+
raise Skynet::ConnectionError.new("Can't find ring finger. #{e.inspect} #{@start_options.inspect}")
|
265
235
|
# rescue RuntimeError => e
|
266
236
|
# raise Skynet::ConnectionError.new("Can't find ring finger. #{}")
|
267
237
|
rescue DRb::DRbConnError, Errno::ECONNREFUSED => e
|
@@ -276,42 +246,46 @@ class Skynet
|
|
276
246
|
####################################
|
277
247
|
|
278
248
|
### XXX ACCEPT MULTIPLE TUPLE SPACES and a flag whether to use replication or failover.
|
279
|
-
|
280
|
-
def self.get_tuple_space
|
281
|
-
|
249
|
+
|
250
|
+
def self.get_tuple_space(options = {})
|
251
|
+
use_ringserver = options[:use_ringserver]
|
252
|
+
ringserver_hosts = options[:ringserver_hosts]
|
253
|
+
drburi = options[:drburi]
|
254
|
+
|
255
|
+
return @@ts if valid_tuplespace?(@@ts)
|
282
256
|
loop do
|
283
257
|
begin
|
284
258
|
DRb.start_service
|
285
|
-
if
|
286
|
-
|
259
|
+
if use_ringserver
|
260
|
+
ringserver_hosts[@@curhostidx] =~ /(.+):(\d+)/
|
287
261
|
host = $1
|
288
262
|
port = $2.to_i
|
289
|
-
@@ts = connect_to_tuple_space(host,port)
|
263
|
+
@@ts = connect_to_tuple_space(host,port,use_ringserver)
|
290
264
|
else
|
291
|
-
drburi =
|
292
|
-
drburi = "druby://#{drburi}" unless drburi =~ %r{druby://}
|
265
|
+
drburi = "druby://#{drburi}" unless drburi =~ %r{druby://}
|
293
266
|
@@ts = get_tuple_space_from_drburi(drburi)
|
294
|
-
|
267
|
+
raise DRb::DRbConnError.new unless valid_tuplespace?(@@ts)
|
268
|
+
info "#{self} CONNECTED TO #{drburi}"
|
295
269
|
end
|
296
270
|
return @@ts
|
297
271
|
rescue RuntimeError => e
|
298
|
-
if
|
299
|
-
|
272
|
+
if ringserver_hosts[@@curhostidx + 1]
|
273
|
+
error "#{self} Couldn't connect to #{ringserver_hosts[@@curhostidx]} trying #{ringserver_hosts[@@curhostidx+1]}"
|
300
274
|
@@curhostidx += 1
|
301
275
|
next
|
302
276
|
else
|
303
|
-
raise Skynet::ConnectionError.new("Can't find ring finger @ #{
|
277
|
+
raise Skynet::ConnectionError.new("Can't find ring finger @ #{ringserver_hosts[@@curhostidx]}. #{e.class} #{e.message}")
|
304
278
|
end
|
305
279
|
rescue Exception => e
|
306
|
-
raise Skynet::ConnectionError.new("Error getting tuplespace @ #{
|
280
|
+
raise Skynet::ConnectionError.new("Error getting tuplespace @ #{ringserver_hosts[@@curhostidx]}. #{e.class} #{e.message}")
|
307
281
|
end
|
308
282
|
end
|
309
283
|
return @@ts
|
310
284
|
end
|
311
|
-
|
312
|
-
def self.connect_to_tuple_space(host,port)
|
313
|
-
|
314
|
-
if
|
285
|
+
|
286
|
+
def self.connect_to_tuple_space(host,port,use_ringserver=Skynet::CONFIG[:TS_USE_RINGSERVER])
|
287
|
+
info "#{self} trying to connect to #{host}:#{port}"
|
288
|
+
if use_ringserver
|
315
289
|
ring_finger = Rinda::RingFinger.new(host,port)
|
316
290
|
ring_server = ring_finger.lookup_ring_any(0.5)
|
317
291
|
|
@@ -320,15 +294,15 @@ class Skynet
|
|
320
294
|
else
|
321
295
|
ts = get_tuple_space_from_drburi("druby://#{host}:#{port}")
|
322
296
|
end
|
323
|
-
|
297
|
+
info "#{self} CONNECTED TO #{host}:#{port}"
|
324
298
|
ts
|
325
299
|
end
|
326
|
-
|
300
|
+
|
327
301
|
def self.get_tuple_space_from_drburi(drburi)
|
328
302
|
DRbObject.new(nil, drburi)
|
329
303
|
end
|
330
304
|
|
331
|
-
def self.
|
305
|
+
def self.valid_tuplespace?(ts)
|
332
306
|
return false unless ts
|
333
307
|
begin
|
334
308
|
ts.read_all([:valid])
|
@@ -66,16 +66,23 @@ module ActiveRecord
|
|
66
66
|
attr_accessor :find_args, :batch_size
|
67
67
|
attr_reader :model_class
|
68
68
|
|
69
|
+
delegate :primary_key, :table_name, :to => :model_klass
|
70
|
+
delegate :execute, :select_all, :to => 'model_klass.connection'
|
71
|
+
|
69
72
|
def initialize(options = {})
|
70
73
|
@find_args = options[:find_args]
|
71
74
|
@batch_size = options[:batch_size] || BATCH_SIZE
|
72
75
|
@model_class = options[:model_class]
|
73
76
|
end
|
74
77
|
|
78
|
+
def model_klass
|
79
|
+
@model_klass ||= model_class.constantize
|
80
|
+
end
|
81
|
+
|
75
82
|
def model_class=(model_c)
|
76
83
|
@model_class = model_c.to_s
|
77
84
|
end
|
78
|
-
|
85
|
+
|
79
86
|
def self.find(*args)
|
80
87
|
if not args.first.is_a?(Hash)
|
81
88
|
args.shift
|
@@ -95,6 +102,11 @@ module ActiveRecord
|
|
95
102
|
def each_range(opts={})
|
96
103
|
opts = opts.clone
|
97
104
|
opts[:id] || opts[:id] = 0
|
105
|
+
count = model_klass.count(:all,:conditions => opts[:conditions], :joins => opts[:joins])
|
106
|
+
if count <= batch_size
|
107
|
+
return yield({"first" => 0, "last" => nil, "cnt" => 0}, 0)
|
108
|
+
end
|
109
|
+
|
98
110
|
rows = chunk_query(opts)
|
99
111
|
# log.error "ROWS, #{rows.pretty_print_inspect}"
|
100
112
|
|
@@ -121,10 +133,8 @@ module ActiveRecord
|
|
121
133
|
end
|
122
134
|
|
123
135
|
def chunk_query(opts={})
|
124
|
-
mc = model_class.constantize
|
125
|
-
table_name = mc.table_name
|
126
136
|
|
127
|
-
conditions = "#{table_name}
|
137
|
+
conditions = "#{table_name}.#{primary_key} > #{opts[:id]} AND ((@t1:=(@t1+1) % #{batch_size})=0)"
|
128
138
|
opts = opts.clone
|
129
139
|
if opts[:conditions].nil? or opts[:conditions].empty?
|
130
140
|
opts[:conditions] = conditions
|
@@ -140,10 +150,10 @@ module ActiveRecord
|
|
140
150
|
# select @t2:=(@t2+1) as cnt, ((@t3:=@t4)+1) as first, @t4:=id as last from profiles where ((@t1:=(@t1+1) % 1000)=0) order by id LIMIT 100;
|
141
151
|
# select (@t2:=(@t2+1) % 2) as evenodd, ((@t3:=@t4)+1) as first, @t4:=id as last from profiles where ((@t1:=(@t1+1) % 1000)=0) order by id LIMIT 100;
|
142
152
|
|
143
|
-
|
144
|
-
sql = "select @t2:=(@t2+1) as cnt, ((@t3:=@t4)+1) as first, @t4:=#{table_name}
|
153
|
+
execute('select @t1:=0, @t2:=-1, @t3:=0, @t4:=0')
|
154
|
+
sql = "select @t2:=(@t2+1) as cnt, ((@t3:=@t4)+1) as first, @t4:=#{table_name}.#{primary_key} as last from #{table_name} #{opts[:joins]} where #{opts[:conditions]} ORDER BY #{table_name}.#{primary_key} #{limit}"
|
145
155
|
# log.error "SQL #{sql}"
|
146
|
-
|
156
|
+
select_all(sql)
|
147
157
|
|
148
158
|
# mc.connection.select_values(mc.send(:construct_finder_sql, :select => "#{mc.table_name}.id", :joins => opts[:joins], :conditions => conditions, :limit => opts[:limit], :order => :id))
|
149
159
|
end
|
@@ -170,7 +180,7 @@ module ActiveRecord
|
|
170
180
|
job.run
|
171
181
|
end
|
172
182
|
|
173
|
-
def
|
183
|
+
def map(klass_or_method=nil,&block)
|
174
184
|
klass_or_method ||= model_class
|
175
185
|
log = Skynet::Logger.get
|
176
186
|
|
@@ -197,7 +207,8 @@ module ActiveRecord
|
|
197
207
|
run_job_for_batch(batches)
|
198
208
|
end
|
199
209
|
|
200
|
-
alias_method :
|
210
|
+
alias_method :each, :map
|
211
|
+
alias_method :mapreduce, :map
|
201
212
|
|
202
213
|
def model_class
|
203
214
|
@model_class || self.class.model_class
|
@@ -220,8 +231,8 @@ module ActiveRecord
|
|
220
231
|
next if data.empty?
|
221
232
|
model_class = data[3].constantize
|
222
233
|
table_name = model_class.table_name
|
223
|
-
conditions = "#{table_name}.
|
224
|
-
conditions += " AND #{table_name}.
|
234
|
+
conditions = "#{table_name}.#{model_class.primary_key} >= #{data[0]}"
|
235
|
+
conditions += " AND #{table_name}.#{model_class.primary_key} <= #{data[1]}" if data[1] > data[0]
|
225
236
|
conditions = "(#{conditions})"
|
226
237
|
# conditions = "ID BETWEEN #{data[0]} and #{data[1]}"
|
227
238
|
if not data[2]
|
data/lib/skynet/skynet_config.rb
CHANGED
@@ -1,18 +1,19 @@
|
|
1
1
|
class Skynet
|
2
|
-
|
3
|
-
|
2
|
+
|
4
3
|
CONFIG = {
|
5
4
|
:ENABLE => true,
|
6
5
|
:SOLO => false,
|
7
|
-
:
|
8
|
-
:
|
9
|
-
:
|
10
|
-
:
|
6
|
+
:APP_ROOT => nil,
|
7
|
+
:SKYNET_LOG_DIR => nil,
|
8
|
+
:SKYNET_PID_DIR => nil,
|
9
|
+
:SKYNET_PID_FILE => "skynet.pid",
|
10
|
+
:SKYNET_LOG_FILE => "skynet.log",
|
11
|
+
:SKYNET_MANAGER_STATS_FILE => "skynet_manager_stats.txt",
|
11
12
|
:SKYNET_LOG_LEVEL => Logger::ERROR,
|
12
|
-
:
|
13
|
+
:SKYNET_LOCAL_MANAGER_PORT => "40000",
|
13
14
|
:MESSAGE_QUEUE_ADAPTER => ("Skynet::MessageQueueAdapter::TupleSpace" || "Skynet::MessageQueueAdapter::Mysql"),
|
14
15
|
:TS_USE_RINGSERVER => true,
|
15
|
-
:
|
16
|
+
:TS_DRBURI => "druby://localhost:47647", # If you do not use RINGSERVER, you must specifiy the DRBURI
|
16
17
|
:TS_SERVER_HOSTS => ["localhost:7647"],
|
17
18
|
:TS_SERVER_START_DELAY => 10,
|
18
19
|
# :MYSQL_QUEUE_DATABASE => "skynet_queue",
|
@@ -22,11 +23,11 @@ class Skynet
|
|
22
23
|
:MYSQL_NEXT_TASK_TIMEOUT => 60,
|
23
24
|
:MYSQL_ADAPTER => "mysql",
|
24
25
|
:MYSQL_HOST => "localhost",
|
25
|
-
:MYSQL_DATABASE =>
|
26
|
-
:MYSQL_USERNAME =>
|
26
|
+
:MYSQL_DATABASE => nil, # 'skynet'
|
27
|
+
:MYSQL_USERNAME => nil,
|
27
28
|
:MYSQL_PASSWORD => "",
|
28
29
|
:NUMBER_OF_WORKERS => 4,
|
29
|
-
:WORKER_CHECK_DELAY =>
|
30
|
+
:WORKER_CHECK_DELAY => 5,
|
30
31
|
:WORKER_MAX_MEMORY => 500,
|
31
32
|
:WORKER_MAX_PROCESSED => 1000,
|
32
33
|
:WORKER_VERSION_CHECK_DELAY => 30,
|
@@ -65,6 +66,10 @@ class Skynet
|
|
65
66
|
ret
|
66
67
|
end
|
67
68
|
end
|
69
|
+
|
70
|
+
def self.config
|
71
|
+
Skynet::Config.new
|
72
|
+
end
|
68
73
|
|
69
74
|
def self.solo(config = {})
|
70
75
|
raise Skynet::Error.new("You provide a code block to Skynet.solo") unless block_given?
|
@@ -100,14 +105,14 @@ class Skynet
|
|
100
105
|
# Skynet.configure(
|
101
106
|
# :ENABLE => true,
|
102
107
|
# :SOLO => false,
|
103
|
-
# :SKYNET_LOG_DIR => LOGDIR,
|
104
108
|
# :SKYNET_PID_DIR => "/tmp",
|
105
|
-
# :
|
106
|
-
# :
|
109
|
+
# :SKYNET_PID_FILE => "skynet.pid",
|
110
|
+
# :SKYNET_LOG_DIR => ENV["HOME"],
|
111
|
+
# :SKYNET_LOG_FILE => "skynet.log",
|
107
112
|
# :SKYNET_LOG_LEVEL => Logger::ERROR,
|
108
113
|
# :SKYNET_LOCAL_MANAGER_URL => "druby://localhost:40000",
|
109
114
|
# :MESSAGE_QUEUE_ADAPTER => "Skynet::MessageQueueAdapter::TupleSpace",
|
110
|
-
# :
|
115
|
+
# :TS_DRBURI => "druby://localhost:47647"
|
111
116
|
# :TS_USE_RINGSERVER => true,
|
112
117
|
# :TS_SERVER_HOSTS => ["localhost:7647"],
|
113
118
|
# :TS_SERVER_START_DELAY => 10,
|
@@ -143,7 +148,7 @@ class Skynet
|
|
143
148
|
# The mysql MQ takes running a migration that comes with skynet_install
|
144
149
|
#
|
145
150
|
# The following only apply to the TupleSpace adapter
|
146
|
-
# :
|
151
|
+
# :TS_DRBURI => "druby://localhost:47647"
|
147
152
|
# :TS_USE_RINGSERVER => true,
|
148
153
|
# :TS_SERVER_HOSTS => ["localhost:7647"],
|
149
154
|
#
|
@@ -162,11 +167,11 @@ class Skynet
|
|
162
167
|
Skynet::CONFIG.each {|k,v| yield k,v}
|
163
168
|
end
|
164
169
|
|
165
|
-
def add_message_queue(queue_name)
|
170
|
+
def self.add_message_queue(queue_name)
|
166
171
|
self.message_queues << queue_name
|
167
172
|
end
|
168
173
|
|
169
|
-
def queue_id_by_name(queue_name)
|
174
|
+
def self.queue_id_by_name(queue_name)
|
170
175
|
if Skynet::CONFIG[:MESSAGE_QUEUES].index(queue_name)
|
171
176
|
return Skynet::CONFIG[:MESSAGE_QUEUES].index(queue_name)
|
172
177
|
else
|
@@ -174,7 +179,7 @@ class Skynet
|
|
174
179
|
end
|
175
180
|
end
|
176
181
|
|
177
|
-
def queue_name_by_id(queue_id)
|
182
|
+
def self.queue_name_by_id(queue_id)
|
178
183
|
queue_id = queue_id.to_i
|
179
184
|
if Skynet::CONFIG[:MESSAGE_QUEUES][queue_id]
|
180
185
|
return Skynet::CONFIG[:MESSAGE_QUEUES][queue_id]
|
@@ -183,9 +188,38 @@ class Skynet
|
|
183
188
|
end
|
184
189
|
end
|
185
190
|
|
191
|
+
def self.logfile_location
|
192
|
+
if skynet_log_file.is_a?(String) and skynet_log_dir
|
193
|
+
skynet_log_dir.sub(/\/$/,'') + "/" + skynet_log_file.sub(/^\//,'')
|
194
|
+
else
|
195
|
+
skynet_log_file
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
def self.pidfile_location
|
200
|
+
if skynet_pid_dir and skynet_pid_file
|
201
|
+
skynet_pid_dir.sub(/\/$/,'') + "/" + skynet_pid_file.sub(/^\//,'')
|
202
|
+
else
|
203
|
+
skynet_pid_dir
|
204
|
+
end
|
205
|
+
end
|
186
206
|
|
207
|
+
def manager_statfile_location
|
208
|
+
if skynet_log_dir.is_a?(String) and skynet_log_dir
|
209
|
+
skynet_log_dir.sub(/\/$/,'') + "/" + skynet_manager_stats_file.sub(/^\//,'')
|
210
|
+
else
|
211
|
+
skynet_log_dir
|
212
|
+
end
|
213
|
+
end
|
214
|
+
def method_missing(name,*args)
|
215
|
+
if self.class.respond_to?(name)
|
216
|
+
self.class.send(name,*args)
|
217
|
+
else
|
218
|
+
self.class.method_missing(name,*args)
|
219
|
+
end
|
220
|
+
end
|
187
221
|
|
188
|
-
def method_missing(name, *args)
|
222
|
+
def self.method_missing(name, *args)
|
189
223
|
name = name.to_s.upcase.to_sym
|
190
224
|
if name.to_s =~ /^(.*)=$/
|
191
225
|
name = $1.to_sym
|