Class: Skynet::Config

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/skynet/skynet_config.rb

Overview

Skynet has many global configuration options. You can access specific options via Skynet::CONFIG = ? You can set many options via

Skynet.configure(:OPTION => option, :ANOTHEROPTION => anotheroption)

If you want specific configuration to only apply to a block of code you can pass configure a block

Skynet.configure(:SOMEOPTION => 'value') do
   run code here
end

Config Options and current defaults:

Skynet.configure(
 :ENABLE                               => true,
 :SOLO                                 => false,
 :SKYNET_PID_DIR                       => "/tmp",
 :SKYNET_PID_FILE                      => "skynet.pid",
 :SKYNET_LOG_DIR                       => ENV["HOME"],
 :SKYNET_LOG_FILE                      => "skynet.log",
 :SKYNET_LOG_LEVEL                     => Logger::ERROR,
 :SKYNET_LOCAL_MANAGER_URL             => "druby://localhost:40000",
 :MESSAGE_QUEUE_ADAPTER                => "Skynet::MessageQueueAdapter::TupleSpace",
 :TS_DRBURI                            => "druby://localhost:47647"
 :TS_USE_RINGSERVER                    => true,
 :TS_SERVER_HOSTS                      => ["localhost:7647"],
 :TS_SERVER_START_DELAY                => 10,
 :MYSQL_QUEUE_DATABASE                 => "skynet_queue",
 :MYSQL_TEMPERATURE_CHANGE_SLEEP       => 40,
 :MYSQL_QUEUE_TEMP_POW                 => 0.6,
 :MYSQL_MESSAGE_QUEUE_TAPLE            => "skynet_message_queues",
 :MYSQL_MESSAGE_QUEUE_TEMP_CHECK_DELAY => 40,
 :MYSQL_NEXT_TASK_TIMEOUT              => 60,
 :WORKER_CHECK_DELAY                   => 40,
 :GUID_GENERATOR                       => nil,
 :NUMBER_OF_WORKERS                    => 4,
 :PERCENTAGE_OF_TASK_ONLY_WORKERS      => 0.7,
 :PERCENTAGE_OF_MASTER_ONLY_WORKERS    => 0.2,
 :MAX_RETRIES                          => 6,
 :DEFAULT_MASTER_RETRY                 => 0,
 :DEFAULT_MAP_RETRY                    => 3,
 :DEFAULT_REDUCE_RETRY                 => 3
 :KEEP_MAP_TASKS                       => false,
 :KEEP_REDUCE_TASKS                    => false
)

ENABLE turns Skynet on or off.

SOLO turns on SOLO mode where Skynet can run in the current process without workers.

Its almost a Skynet emulation mode

MESSAGE_QUEUE_ADAPTER Skynet comes with 2 message queue adaptors

Skynet::MessageQueueAdapter::TupleSpace 
Skynet::MessageQueueAdapter::Mysql

The default is TupleSpace which is an in memory database. The mysql MQ takes running a migration that comes with skynet_install

The following only apply to the TupleSpace adapter

:TS_DRBURI                            => "druby://localhost:47647"
:TS_USE_RINGSERVER                    => true,
:TS_SERVER_HOSTS                      => ["localhost:7647"],

The following only apply to the Mysql adapter

:MYSQL_QUEUE_DATABASE                 => "skynet_queue",
:MYSQL_TEMPERATURE_CHANGE_SLEEP       => 40,
:MYSQL_QUEUE_TEMP_POW                 => 0.6,
:MYSQL_MESSAGE_QUEUE_TAPLE            => "skynet_message_queues",
:MYSQL_MESSAGE_QUEUE_TEMP_CHECK_DELAY => 40,
:MYSQL_NEXT_TASK_TIMEOUT              => 60,

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Enumerable

#mapreduce

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



214
215
216
217
218
219
220
# File 'lib/skynet/skynet_config.rb', line 214

def method_missing(name,*args)
  if self.class.respond_to?(name)
    self.class.send(name,*args)
  else        
    self.class.method_missing(name,*args)
  end
end

Class Method Details

.add_message_queue(queue_name) ⇒ Object



170
171
172
# File 'lib/skynet/skynet_config.rb', line 170

def self.add_message_queue(queue_name)
  self.message_queues << queue_name
end

.logfile_locationObject



191
192
193
194
195
196
197
# File 'lib/skynet/skynet_config.rb', line 191

def self.logfile_location
  if skynet_log_file.is_a?(String) and skynet_log_dir
    skynet_log_dir.sub(/\/$/,'') + "/" + skynet_log_file.sub(/^\//,'')
  else
    skynet_log_file
  end
end

.method_missing(name, *args) ⇒ Object



222
223
224
225
226
227
228
229
230
# File 'lib/skynet/skynet_config.rb', line 222

def self.method_missing(name, *args)
  name = name.to_s.upcase.to_sym
  if name.to_s =~ /^(.*)=$/
    name = $1.to_sym
    Skynet::CONFIG[name] = args.first
  else
    Skynet::CONFIG[name]
  end
end

.pidfile_locationObject



199
200
201
202
203
204
205
# File 'lib/skynet/skynet_config.rb', line 199

def self.pidfile_location
  if skynet_pid_dir and skynet_pid_file
    skynet_pid_dir.sub(/\/$/,'') + "/" + skynet_pid_file.sub(/^\//,'')
  else
    skynet_pid_dir
  end
end

.queue_id_by_name(queue_name) ⇒ Object



174
175
176
177
178
179
180
# File 'lib/skynet/skynet_config.rb', line 174

def self.queue_id_by_name(queue_name)
  if Skynet::CONFIG[:MESSAGE_QUEUES].index(queue_name)
    return Skynet::CONFIG[:MESSAGE_QUEUES].index(queue_name)
  else     
    raise Skynet::Error("#{queue_name} is not a valid queue")
  end
end

.queue_name_by_id(queue_id) ⇒ Object



182
183
184
185
186
187
188
189
# File 'lib/skynet/skynet_config.rb', line 182

def self.queue_name_by_id(queue_id)               
  queue_id = queue_id.to_i
  if Skynet::CONFIG[:MESSAGE_QUEUES][queue_id]
    return Skynet::CONFIG[:MESSAGE_QUEUES][queue_id]
  else     
    raise Skynet::Error("#{queue_id} is not a valid queue_id")
  end
end

Instance Method Details

#eachObject



166
167
168
# File 'lib/skynet/skynet_config.rb', line 166

def each
  Skynet::CONFIG.each {|k,v| yield k,v}
end

#manager_statfile_locationObject



207
208
209
210
211
212
213
# File 'lib/skynet/skynet_config.rb', line 207

def manager_statfile_location
  if skynet_log_dir.is_a?(String) and skynet_log_dir
    skynet_log_dir.sub(/\/$/,'') + "/" + skynet_manager_stats_file.sub(/^\//,'')
  else
    skynet_log_dir
  end
end