Class: Msf::TaskManager::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/msf/core/task_manager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(proc, timeout = nil) ⇒ Task

Create a new task


24
25
26
27
28
29
30
# File 'lib/msf/core/task_manager.rb', line 24

def initialize(proc,timeout=nil)
  self.proc    = proc
  self.status  = :new
  self.created = Time.now
  self.timeout = timeout
  self.source  = caller
end

Instance Attribute Details

#completedObject

Returns the value of attribute completed


15
16
17
# File 'lib/msf/core/task_manager.rb', line 15

def completed
  @completed
end

#createdObject

Returns the value of attribute created


14
15
16
# File 'lib/msf/core/task_manager.rb', line 14

def created
  @created
end

#exceptionObject

Returns the value of attribute exception


19
20
21
# File 'lib/msf/core/task_manager.rb', line 19

def exception
  @exception
end

#procObject

Returns the value of attribute proc


17
18
19
# File 'lib/msf/core/task_manager.rb', line 17

def proc
  @proc
end

#sourceObject

Returns the value of attribute source


18
19
20
# File 'lib/msf/core/task_manager.rb', line 18

def source
  @source
end

#statusObject

Returns the value of attribute status


16
17
18
# File 'lib/msf/core/task_manager.rb', line 16

def status
  @status
end

#timeoutObject

Returns the value of attribute timeout


13
14
15
# File 'lib/msf/core/task_manager.rb', line 13

def timeout
  @timeout
end

Instance Method Details

#durationObject

Task duration in seconds (float)


35
36
37
38
# File 'lib/msf/core/task_manager.rb', line 35

def duration
  etime = self.completed || Time.now
  etime.to_f - self.created.to_f
end

#run(*args) ⇒ Object

Run the associated proc


50
51
52
# File 'lib/msf/core/task_manager.rb', line 50

def run(*args)
  self.proc.call(*args) if self.proc
end

#waitObject


40
41
42
43
44
45
# File 'lib/msf/core/task_manager.rb', line 40

def wait
  while self.status == :new
    ::IO.select(nil,nil,nil,0.10)
  end
  return self.status
end