Class: Skynet::Task

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#dataObject (readonly)

Returns the value of attribute data.



11
12
13
# File 'lib/skynet/skynet_task.rb', line 11

def data
  @data
end

#map_or_reduceObject (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

#nameObject

Returns the value of attribute name.



12
13
14
# File 'lib/skynet/skynet_task.rb', line 12

def name
  @name
end

#processObject

Returns the value of attribute process.



11
12
13
# File 'lib/skynet/skynet_task.rb', line 11

def process
  @process
end

#resultObject (readonly)

Returns the value of attribute result.



11
12
13
# File 'lib/skynet/skynet_task.rb', line 11

def result
  @result
end

#result_timeoutObject

Returns the value of attribute result_timeout.



12
13
14
# File 'lib/skynet/skynet_task.rb', line 12

def result_timeout
  @result_timeout
end

#tupleObject

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_descObject



16
17
18
# File 'lib/skynet/skynet_task.rb', line 16

def self.debug_class_desc
  "TASK"
end

Instance Method Details

#can_marshal?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/skynet/skynet_task.rb', line 40

def can_marshal?
  @marshalable
end

#runObject



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_idObject



52
53
54
# File 'lib/skynet/skynet_task.rb', line 52

def task_id
  @task_id.to_i
end

#task_or_masterObject



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