timocratic-skynet 0.9.4
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +152 -0
- data/License.txt +20 -0
- data/Manifest.txt +144 -0
- data/README.txt +178 -0
- data/Rakefile +5 -0
- data/app_generators/skynet_install/USAGE +5 -0
- data/app_generators/skynet_install/skynet_install_generator.rb +94 -0
- data/app_generators/skynet_install/templates/migration.rb +43 -0
- 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_mysql_schema.sql +33 -0
- data/bin/skynet +71 -0
- data/bin/skynet_install +36 -0
- data/bin/skynet_tuplespace_server +74 -0
- data/config/hoe.rb +75 -0
- data/config/requirements.rb +17 -0
- 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/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 +95 -0
- data/lib/skynet/mapreduce_helper.rb +74 -0
- data/lib/skynet/mapreduce_test.rb +56 -0
- data/lib/skynet/message_queue_adapters/message_queue_adapter.rb +70 -0
- data/lib/skynet/message_queue_adapters/mysql.rb +509 -0
- data/lib/skynet/message_queue_adapters/tuple_space.rb +316 -0
- data/lib/skynet/skynet_active_record_extensions.rb +280 -0
- data/lib/skynet/skynet_config.rb +232 -0
- data/lib/skynet/skynet_console.rb +50 -0
- data/lib/skynet/skynet_console_helper.rb +66 -0
- data/lib/skynet/skynet_debugger.rb +138 -0
- data/lib/skynet/skynet_guid_generator.rb +68 -0
- data/lib/skynet/skynet_job.rb +892 -0
- data/lib/skynet/skynet_launcher.rb +40 -0
- data/lib/skynet/skynet_logger.rb +62 -0
- data/lib/skynet/skynet_manager.rb +706 -0
- data/lib/skynet/skynet_message.rb +359 -0
- data/lib/skynet/skynet_message_queue.rb +136 -0
- data/lib/skynet/skynet_partitioners.rb +96 -0
- data/lib/skynet/skynet_ruby_extensions.rb +53 -0
- data/lib/skynet/skynet_task.rb +118 -0
- data/lib/skynet/skynet_tuplespace_server.rb +83 -0
- data/lib/skynet/skynet_worker.rb +451 -0
- data/lib/skynet/version.rb +9 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +74 -0
- data/setup.rb +1585 -0
- data/tasks/deployment.rake +34 -0
- data/tasks/environment.rake +7 -0
- data/tasks/website.rake +17 -0
- data/test/test_active_record_extensions.rb +138 -0
- data/test/test_generator_helper.rb +20 -0
- data/test/test_helper.rb +10 -0
- data/test/test_mysql_message_queue_adapter.rb +263 -0
- data/test/test_skynet.rb +19 -0
- data/test/test_skynet_install_generator.rb +49 -0
- data/test/test_skynet_job.rb +717 -0
- data/test/test_skynet_manager.rb +157 -0
- data/test/test_skynet_message.rb +229 -0
- data/test/test_skynet_task.rb +24 -0
- data/test/test_tuplespace_message_queue.rb +174 -0
- data/website/index.html +181 -0
- data/website/index.txt +98 -0
- data/website/javascripts/rounded_corners_lite.inc.js +285 -0
- data/website/stylesheets/screen.css +138 -0
- data/website/template.rhtml +48 -0
- metadata +247 -0
@@ -0,0 +1,232 @@
|
|
1
|
+
class Skynet
|
2
|
+
|
3
|
+
CONFIG = {
|
4
|
+
:ENABLE => true,
|
5
|
+
:SOLO => false,
|
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",
|
12
|
+
:SKYNET_LOG_LEVEL => Logger::ERROR,
|
13
|
+
:SKYNET_LOCAL_MANAGER_PORT => "40000",
|
14
|
+
:MESSAGE_QUEUE_ADAPTER => ("Skynet::MessageQueueAdapter::TupleSpace" || "Skynet::MessageQueueAdapter::Mysql"),
|
15
|
+
:TS_USE_RINGSERVER => true,
|
16
|
+
:TS_DRBURI => "druby://localhost:47647", # If you do not use RINGSERVER, you must specifiy the DRBURI
|
17
|
+
:TS_SERVER_HOSTS => ["localhost:7647"],
|
18
|
+
:TS_SERVER_START_DELAY => 10,
|
19
|
+
# :MYSQL_QUEUE_DATABASE => "skynet_queue",
|
20
|
+
:MYSQL_TEMPERATURE_CHANGE_SLEEP => 40,
|
21
|
+
:MYSQL_MESSAGE_QUEUE_TAPLE => "skynet_message_queues",
|
22
|
+
:MYSQL_MESSAGE_QUEUE_TEMP_CHECK_DELAY => 40,
|
23
|
+
:MYSQL_NEXT_TASK_TIMEOUT => 60,
|
24
|
+
:MYSQL_ADAPTER => "mysql",
|
25
|
+
:MYSQL_HOST => "localhost",
|
26
|
+
:MYSQL_DATABASE => nil, # 'skynet'
|
27
|
+
:MYSQL_USERNAME => nil,
|
28
|
+
:MYSQL_PASSWORD => "",
|
29
|
+
:NUMBER_OF_WORKERS => 4,
|
30
|
+
:WORKER_CHECK_DELAY => 5,
|
31
|
+
:WORKER_MAX_MEMORY => 500,
|
32
|
+
:WORKER_MAX_PROCESSED => 1000,
|
33
|
+
:WORKER_VERSION_CHECK_DELAY => 30,
|
34
|
+
# :GUID_GENERATOR => nil,
|
35
|
+
:PERCENTAGE_OF_TASK_ONLY_WORKERS => 0.7,
|
36
|
+
:PERCENTAGE_OF_MASTER_ONLY_WORKERS => 0.2,
|
37
|
+
:MAX_RETRIES => 6,
|
38
|
+
:DEFAULT_MASTER_RETRY => 0,
|
39
|
+
:DEFAULT_MAP_RETRY => 3,
|
40
|
+
:DEFAULT_REDUCE_RETRY => 3,
|
41
|
+
:DEFAULT_KEEP_MAP_TASKS => 1,
|
42
|
+
:DEFAULT_KEEP_REDUCE_TASKS => 1,
|
43
|
+
:MESSAGE_QUEUES => ['first', 'second', 'third', 'fourth', 'fifth', 'sixth', 'seventh', 'eighth', 'nineth']
|
44
|
+
} unless defined?(CONFIG)
|
45
|
+
|
46
|
+
def self.silent
|
47
|
+
if block_given?
|
48
|
+
Skynet.configure(:SKYNET_LOG_LEVEL => 10) do
|
49
|
+
yield
|
50
|
+
end
|
51
|
+
else
|
52
|
+
raise Error.new("Please provide a block to Skynet.silent")
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.configure(config={})
|
57
|
+
old_config = CONFIG.dup
|
58
|
+
config.each {|k,v| CONFIG[k] = v}
|
59
|
+
Skynet::Logger.log = nil
|
60
|
+
if block_given?
|
61
|
+
ret = yield
|
62
|
+
CONFIG.keys.each do |key|
|
63
|
+
CONFIG.delete(key)
|
64
|
+
end
|
65
|
+
old_config.each {|k,v| CONFIG[k] = v}
|
66
|
+
ret
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.config
|
71
|
+
Skynet::Config.new
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.solo(config = {})
|
75
|
+
raise Skynet::Error.new("You provide a code block to Skynet.solo") unless block_given?
|
76
|
+
result = nil
|
77
|
+
Skynet::Logger.log = nil
|
78
|
+
begin
|
79
|
+
config[:ENABLE] = true
|
80
|
+
config[:SOLO] = true
|
81
|
+
config[:SKYNET_LOG_FILE] ||= STDOUT
|
82
|
+
config[:SKYNET_LOG_LEVEL] ||= Logger::ERROR
|
83
|
+
configure(config) do
|
84
|
+
result = yield
|
85
|
+
end
|
86
|
+
rescue Exception => e
|
87
|
+
error "Something bad happened #{e.inspect} #{e.backtrace.join("\n")}"
|
88
|
+
end
|
89
|
+
return result
|
90
|
+
end
|
91
|
+
|
92
|
+
# Skynet has many global configuration options.
|
93
|
+
# You can access specific options via Skynet::CONFIG[:OPTION] = ?
|
94
|
+
# You can set many options via
|
95
|
+
#
|
96
|
+
# Skynet.configure(:OPTION => option, :ANOTHEROPTION => anotheroption)
|
97
|
+
#
|
98
|
+
# If you want specific configuration to only apply to a block of code you can pass configure a block
|
99
|
+
#
|
100
|
+
# Skynet.configure(:SOMEOPTION => 'value') do
|
101
|
+
# run code here
|
102
|
+
# end
|
103
|
+
#
|
104
|
+
# Config Options and current defaults:
|
105
|
+
# Skynet.configure(
|
106
|
+
# :ENABLE => true,
|
107
|
+
# :SOLO => false,
|
108
|
+
# :SKYNET_PID_DIR => "/tmp",
|
109
|
+
# :SKYNET_PID_FILE => "skynet.pid",
|
110
|
+
# :SKYNET_LOG_DIR => ENV["HOME"],
|
111
|
+
# :SKYNET_LOG_FILE => "skynet.log",
|
112
|
+
# :SKYNET_LOG_LEVEL => Logger::ERROR,
|
113
|
+
# :SKYNET_LOCAL_MANAGER_URL => "druby://localhost:40000",
|
114
|
+
# :MESSAGE_QUEUE_ADAPTER => "Skynet::MessageQueueAdapter::TupleSpace",
|
115
|
+
# :TS_DRBURI => "druby://localhost:47647"
|
116
|
+
# :TS_USE_RINGSERVER => true,
|
117
|
+
# :TS_SERVER_HOSTS => ["localhost:7647"],
|
118
|
+
# :TS_SERVER_START_DELAY => 10,
|
119
|
+
# :MYSQL_QUEUE_DATABASE => "skynet_queue",
|
120
|
+
# :MYSQL_TEMPERATURE_CHANGE_SLEEP => 40,
|
121
|
+
# :MYSQL_QUEUE_TEMP_POW => 0.6,
|
122
|
+
# :MYSQL_MESSAGE_QUEUE_TAPLE => "skynet_message_queues",
|
123
|
+
# :MYSQL_MESSAGE_QUEUE_TEMP_CHECK_DELAY => 40,
|
124
|
+
# :MYSQL_NEXT_TASK_TIMEOUT => 60,
|
125
|
+
# :WORKER_CHECK_DELAY => 40,
|
126
|
+
# :GUID_GENERATOR => nil,
|
127
|
+
# :NUMBER_OF_WORKERS => 4,
|
128
|
+
# :PERCENTAGE_OF_TASK_ONLY_WORKERS => 0.7,
|
129
|
+
# :PERCENTAGE_OF_MASTER_ONLY_WORKERS => 0.2,
|
130
|
+
# :MAX_RETRIES => 6,
|
131
|
+
# :DEFAULT_MASTER_RETRY => 0,
|
132
|
+
# :DEFAULT_MAP_RETRY => 3,
|
133
|
+
# :DEFAULT_REDUCE_RETRY => 3
|
134
|
+
# :KEEP_MAP_TASKS => false,
|
135
|
+
# :KEEP_REDUCE_TASKS => false
|
136
|
+
# )
|
137
|
+
#
|
138
|
+
# ENABLE turns Skynet on or off.
|
139
|
+
#
|
140
|
+
# SOLO turns on SOLO mode where Skynet can run in the current process without workers.
|
141
|
+
# Its almost a Skynet emulation mode
|
142
|
+
#
|
143
|
+
# MESSAGE_QUEUE_ADAPTER
|
144
|
+
# Skynet comes with 2 message queue adaptors
|
145
|
+
# Skynet::MessageQueueAdapter::TupleSpace
|
146
|
+
# Skynet::MessageQueueAdapter::Mysql
|
147
|
+
# The default is TupleSpace which is an in memory database.
|
148
|
+
# The mysql MQ takes running a migration that comes with skynet_install
|
149
|
+
#
|
150
|
+
# The following only apply to the TupleSpace adapter
|
151
|
+
# :TS_DRBURI => "druby://localhost:47647"
|
152
|
+
# :TS_USE_RINGSERVER => true,
|
153
|
+
# :TS_SERVER_HOSTS => ["localhost:7647"],
|
154
|
+
#
|
155
|
+
# The following only apply to the Mysql adapter
|
156
|
+
# :MYSQL_QUEUE_DATABASE => "skynet_queue",
|
157
|
+
# :MYSQL_TEMPERATURE_CHANGE_SLEEP => 40,
|
158
|
+
# :MYSQL_QUEUE_TEMP_POW => 0.6,
|
159
|
+
# :MYSQL_MESSAGE_QUEUE_TAPLE => "skynet_message_queues",
|
160
|
+
# :MYSQL_MESSAGE_QUEUE_TEMP_CHECK_DELAY => 40,
|
161
|
+
# :MYSQL_NEXT_TASK_TIMEOUT => 60,
|
162
|
+
|
163
|
+
class Config
|
164
|
+
include Enumerable
|
165
|
+
|
166
|
+
def each
|
167
|
+
Skynet::CONFIG.each {|k,v| yield k,v}
|
168
|
+
end
|
169
|
+
|
170
|
+
def self.add_message_queue(queue_name)
|
171
|
+
self.message_queues << queue_name
|
172
|
+
end
|
173
|
+
|
174
|
+
def self.queue_id_by_name(queue_name)
|
175
|
+
if Skynet::CONFIG[:MESSAGE_QUEUES].index(queue_name)
|
176
|
+
return Skynet::CONFIG[:MESSAGE_QUEUES].index(queue_name)
|
177
|
+
else
|
178
|
+
raise Skynet::Error("#{queue_name} is not a valid queue")
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
def self.queue_name_by_id(queue_id)
|
183
|
+
queue_id = queue_id.to_i
|
184
|
+
if Skynet::CONFIG[:MESSAGE_QUEUES][queue_id]
|
185
|
+
return Skynet::CONFIG[:MESSAGE_QUEUES][queue_id]
|
186
|
+
else
|
187
|
+
raise Skynet::Error("#{queue_id} is not a valid queue_id")
|
188
|
+
end
|
189
|
+
end
|
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
|
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
|
221
|
+
|
222
|
+
def self.method_missing(name, *args)
|
223
|
+
name = name.to_s.upcase.to_sym
|
224
|
+
if name.to_s =~ /^(.*)=$/
|
225
|
+
name = $1.to_sym
|
226
|
+
Skynet::CONFIG[name] = args.first
|
227
|
+
else
|
228
|
+
Skynet::CONFIG[name]
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
class Skynet
|
2
|
+
class Console
|
3
|
+
def self.start(libs=[])
|
4
|
+
require 'rubygems'
|
5
|
+
require 'optparse'
|
6
|
+
require 'skynet'
|
7
|
+
require "skynet_console_helper"
|
8
|
+
require "irb/completion"
|
9
|
+
require "irb"
|
10
|
+
|
11
|
+
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
|
12
|
+
|
13
|
+
options = {
|
14
|
+
:irb => irb,
|
15
|
+
:required_libs => []
|
16
|
+
}
|
17
|
+
|
18
|
+
OptionParser.new do |opt|
|
19
|
+
opt.banner = "Usage: skynet console [options]"
|
20
|
+
opt.on("--irb=[#{irb}]", 'Invoke a different irb.') { |v| options[:irb] = v }
|
21
|
+
opt.on('-r', '--required LIBRARY', 'Require the specified libraries. To include multiple libraries, include multiple -r options. ie. -r skynet -r fileutils') do |v|
|
22
|
+
options[:required_libs] << File.expand_path(v)
|
23
|
+
end
|
24
|
+
opt.parse!(ARGV)
|
25
|
+
end
|
26
|
+
|
27
|
+
options[:required_libs] + libs
|
28
|
+
options[:required_libs].uniq.each do |lib|
|
29
|
+
require lib
|
30
|
+
end
|
31
|
+
|
32
|
+
IRB.setup(Skynet::CONFIG[:LAUNCHER_PATH])
|
33
|
+
IRB.conf[:PROMPT][:SKYNET] = IRB.conf[:PROMPT][:SIMPLE].dup
|
34
|
+
IRB.conf[:PROMPT][:SKYNET][:PROMPT_I] = "skynet>>"
|
35
|
+
|
36
|
+
IRB.conf[:PROMPT_MODE] = :SKYNET
|
37
|
+
irb = IRB::Irb.new()
|
38
|
+
IRB.conf[:MAIN_CONTEXT] = irb.context
|
39
|
+
irb.context.workspace.main.extend Skynet::ConsoleHelper
|
40
|
+
|
41
|
+
trap("SIGINT") do
|
42
|
+
irb.signal_handle
|
43
|
+
end
|
44
|
+
|
45
|
+
catch(:IRB_EXIT) do
|
46
|
+
irb.eval_input
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module Skynet::ConsoleHelper
|
2
|
+
# All of these commands can be run at the 'skynet console'.
|
3
|
+
|
4
|
+
def log
|
5
|
+
Skynet::Logger.get
|
6
|
+
end
|
7
|
+
|
8
|
+
def mq
|
9
|
+
@mq ||= Skynet::MessageQueue.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def stats
|
13
|
+
mq.stats
|
14
|
+
end
|
15
|
+
|
16
|
+
def increment_worker_version
|
17
|
+
mq.increment_worker_version
|
18
|
+
end
|
19
|
+
|
20
|
+
def get_worker_version
|
21
|
+
mq.get_worker_version
|
22
|
+
end
|
23
|
+
|
24
|
+
def set_worker_version(*args)
|
25
|
+
mq.set_worker_version(*args)
|
26
|
+
end
|
27
|
+
|
28
|
+
def manager
|
29
|
+
@manager ||= Skynet::Manager.get
|
30
|
+
end
|
31
|
+
|
32
|
+
def add_lib(lib)
|
33
|
+
manager.required_libs << File.expand_path(lib)
|
34
|
+
manager.restart_workers
|
35
|
+
end
|
36
|
+
|
37
|
+
def restart_workers
|
38
|
+
manager.restart_workers
|
39
|
+
end
|
40
|
+
|
41
|
+
def add_workers(num)
|
42
|
+
manager.add_workers(num)
|
43
|
+
end
|
44
|
+
|
45
|
+
def remove_workers(num)
|
46
|
+
manager.remove_workers(num)
|
47
|
+
end
|
48
|
+
|
49
|
+
# ===============
|
50
|
+
# = Doesnt work =
|
51
|
+
# ===============
|
52
|
+
# def help
|
53
|
+
# puts <<-HELP
|
54
|
+
# mq
|
55
|
+
# stats
|
56
|
+
# increment_worker_version
|
57
|
+
# get_worker_version
|
58
|
+
# set_worker_version(version)
|
59
|
+
# manager
|
60
|
+
# add_lib(library_to_include) -- forces a restart
|
61
|
+
# restart_workers
|
62
|
+
# add_workers(number_of_workers)
|
63
|
+
# remove_workers(number_of_workers)
|
64
|
+
# HELP
|
65
|
+
# end
|
66
|
+
end
|
@@ -0,0 +1,138 @@
|
|
1
|
+
# ==SkynetDebugger
|
2
|
+
# The SkynetDebugger is a module you can include in any of your classes that will give you easy access
|
3
|
+
# to the Skynet::Logger. including SkynetDebugger gives you a number of logging methods. Each logging method
|
4
|
+
# lets you pass a message as well as an optional number of objects which will be pretty_printed after your message.
|
5
|
+
# Log lines print with their log level, PID, time, class, and message. eg.
|
6
|
+
#
|
7
|
+
# [WARN] #78002 2008-04-11 14:17:15.363167 <WORKER-78002> Exiting...
|
8
|
+
#
|
9
|
+
# You can set the log_level and log_file with (See Skynet::Config)
|
10
|
+
# Skynet::CONFIG[:SKYNET_LOG_FILE]
|
11
|
+
# Skynet::CONFIG[:SKYNET_LOG_LEVEL]
|
12
|
+
#
|
13
|
+
# Possible log levels include
|
14
|
+
# Logger::DEBUG
|
15
|
+
# Logger::INFO
|
16
|
+
# Logger::WARN
|
17
|
+
# Logger::ERROR
|
18
|
+
# Logger::FATAL
|
19
|
+
#
|
20
|
+
# ==Methods
|
21
|
+
# log - returns the Skynet::Logger
|
22
|
+
#
|
23
|
+
# debug(msg,*objects_to_inspect)
|
24
|
+
#
|
25
|
+
# info(msg,*objects_to_inspect)
|
26
|
+
#
|
27
|
+
# warn(msg,*objects_to_inspect)
|
28
|
+
#
|
29
|
+
# error(msg,*objects_to_inspect)
|
30
|
+
#
|
31
|
+
# fatal(msg,*objects_to_inspect)
|
32
|
+
#
|
33
|
+
# printlog(msg,*objects_to_inspect) #printlog will ALWAYS print to the log as log level [LOG] regardless of the LOG_LEVEL
|
34
|
+
module SkynetDebugger
|
35
|
+
|
36
|
+
def self.included(base)
|
37
|
+
base.extend ClassMethods
|
38
|
+
end
|
39
|
+
|
40
|
+
def log
|
41
|
+
self.class.log
|
42
|
+
end
|
43
|
+
|
44
|
+
def args_pp(*args)
|
45
|
+
self.class.args_pp(*args)
|
46
|
+
end
|
47
|
+
|
48
|
+
def debug(*args)
|
49
|
+
self.class.debug(*args)
|
50
|
+
end
|
51
|
+
|
52
|
+
def info(*args)
|
53
|
+
self.class.info(*args)
|
54
|
+
end
|
55
|
+
|
56
|
+
def warn(*args)
|
57
|
+
self.class.warn(*args)
|
58
|
+
end
|
59
|
+
|
60
|
+
def error(*args)
|
61
|
+
self.class.error(*args)
|
62
|
+
end
|
63
|
+
|
64
|
+
def fatal(*args)
|
65
|
+
self.class.fatal(*args)
|
66
|
+
end
|
67
|
+
|
68
|
+
def printlog(*args)
|
69
|
+
self.class.printlog(*args)
|
70
|
+
end
|
71
|
+
|
72
|
+
def debug_header
|
73
|
+
self.class.debug_header
|
74
|
+
end
|
75
|
+
|
76
|
+
def stderr(*args)
|
77
|
+
self.class.stderr
|
78
|
+
end
|
79
|
+
|
80
|
+
def stdout(*args)
|
81
|
+
self.class.stdout
|
82
|
+
end
|
83
|
+
|
84
|
+
module ClassMethods
|
85
|
+
|
86
|
+
def debug_class_desc
|
87
|
+
self.to_s
|
88
|
+
end
|
89
|
+
|
90
|
+
def debug_header
|
91
|
+
t = Time.now
|
92
|
+
"##{$$} #{t.strftime("%Y-%m-%d %H:%M:%S")}.#{t.usec} <#{debug_class_desc}>"
|
93
|
+
end
|
94
|
+
|
95
|
+
# log
|
96
|
+
def log
|
97
|
+
Skynet::Logger.get
|
98
|
+
end
|
99
|
+
|
100
|
+
def args_pp(*args)
|
101
|
+
"#{args.length > 0 ? args.pretty_print_inspect : ''}"
|
102
|
+
end
|
103
|
+
|
104
|
+
def debug(msg,*args)
|
105
|
+
log.debug "[DEBUG] #{debug_header} #{msg} #{args_pp(*args)}"
|
106
|
+
end
|
107
|
+
|
108
|
+
def info(msg, *args)
|
109
|
+
log.info "[INFO] #{debug_header} #{msg} #{args_pp(*args)}"
|
110
|
+
end
|
111
|
+
|
112
|
+
def warn(msg, *args)
|
113
|
+
log.warn "[WARN] #{debug_header} #{msg} #{args_pp(*args)}"
|
114
|
+
end
|
115
|
+
|
116
|
+
def error(msg, *args)
|
117
|
+
log.error "[ERROR] #{debug_header} #{msg} #{args_pp(*args)}"
|
118
|
+
end
|
119
|
+
|
120
|
+
def fatal(msg, *args)
|
121
|
+
log.fatal "[FATAL] #{debug_header} #{msg} #{args_pp(*args)}"
|
122
|
+
end
|
123
|
+
|
124
|
+
def printlog(msg, *args)
|
125
|
+
log.unknown "[LOG] #{debug_header} #{msg} #{args_pp(*args)}"
|
126
|
+
end
|
127
|
+
|
128
|
+
def stderr(msg, *args)
|
129
|
+
$stderr.puts "#{debug_header} #{msg} #{args_pp(*args)}"
|
130
|
+
end
|
131
|
+
|
132
|
+
def stdout(msg, *args)
|
133
|
+
$stdout.puts "#{debug_header} #{msg} #{args_pp(*args)}"
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
137
|
+
|
138
|
+
end
|