Class: Skynet::Task
- Inherits:
-
Object
- Object
- Skynet::Task
- Includes:
- SkynetDebugger
- Defined in:
- lib/skynet/skynet_task.rb,
lib/skynet/skynet_tuplespace_server.rb
Defined Under Namespace
Classes: ConstructorError
Constant Summary collapse
- @@log =
nil
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#map_or_reduce ⇒ Object
readonly
Returns the value of attribute map_or_reduce.
-
#name ⇒ Object
Returns the value of attribute name.
-
#process ⇒ Object
Returns the value of attribute process.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
-
#result_timeout ⇒ Object
Returns the value of attribute result_timeout.
-
#tuple ⇒ Object
Returns the value of attribute tuple.
Class Method Summary collapse
Instance Method Summary collapse
- #can_marshal? ⇒ Boolean
-
#initialize(opts = {}) ⇒ Task
constructor
A new instance of Task.
- #run ⇒ Object
- #task_id ⇒ Object
- #task_or_master ⇒ Object
Methods included from SkynetDebugger
#args_pp, #debug, #debug_header, #error, #fatal, included, #info, #log, #warn
Constructor Details
#initialize(opts = {}) ⇒ Task
Returns a new instance of Task.
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/skynet/skynet_task.rb', line 20 def initialize(opts = {}) unless opts[:task_id] and opts[:process] and opts[:map_or_reduce] raise ConstructorError.new("Must provide task_id, process and map_or_reduce") end @marshalable = true @task_id = opts[:task_id].to_i @data = opts[:data] self.process = opts[:process] @name = opts[:name] @map_or_reduce = opts[:map_or_reduce] @result_timeout = opts[:result_timeout] end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
11 12 13 |
# File 'lib/skynet/skynet_task.rb', line 11 def data @data end |
#map_or_reduce ⇒ Object (readonly)
Returns the value of attribute map_or_reduce.
11 12 13 |
# File 'lib/skynet/skynet_task.rb', line 11 def map_or_reduce @map_or_reduce end |
#name ⇒ Object
Returns the value of attribute name.
12 13 14 |
# File 'lib/skynet/skynet_task.rb', line 12 def name @name end |
#process ⇒ Object
Returns the value of attribute process.
11 12 13 |
# File 'lib/skynet/skynet_task.rb', line 11 def process @process end |
#result ⇒ Object (readonly)
Returns the value of attribute result.
11 12 13 |
# File 'lib/skynet/skynet_task.rb', line 11 def result @result end |
#result_timeout ⇒ Object
Returns the value of attribute result_timeout.
12 13 14 |
# File 'lib/skynet/skynet_task.rb', line 12 def result_timeout @result_timeout end |
#tuple ⇒ Object
Returns the value of attribute tuple.
12 13 14 |
# File 'lib/skynet/skynet_task.rb', line 12 def tuple @tuple end |
Class Method Details
.debug_class_desc ⇒ Object
16 17 18 |
# File 'lib/skynet/skynet_task.rb', line 16 def self.debug_class_desc "TASK" end |
Instance Method Details
#can_marshal? ⇒ Boolean
40 41 42 |
# File 'lib/skynet/skynet_task.rb', line 40 def can_marshal? @marshalable end |
#run ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/skynet/skynet_task.rb', line 56 def run debug "running task #{name} task_id:#{task_id} MorR:#{map_or_reduce} PROCESS CLASS: #{@process.class}" begin if @process.class == Proc debug " - #{@map_or_reduce} using Proc" @process.call @data elsif @map_or_reduce == :master debug " - as master" job = Skynet::Job.new(@process) job.run elsif @process.class == String debug " - #{@map_or_reduce} using class #{@process}" @process.constantize.send(@map_or_reduce,@data) end rescue Exception => e error "Error running task #{e.inspect} TASK:", self, e.backtrace.join("\n") end end |
#task_id ⇒ Object
52 53 54 |
# File 'lib/skynet/skynet_task.rb', line 52 def task_id @task_id.to_i end |
#task_or_master ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/skynet/skynet_task.rb', line 44 def task_or_master if @map_or_reduce == :master @map_or_reduce else :task end end |