Class: ScbiMapreduce::WorkManagerData

Inherits:
Object
  • Object
show all
Defined in:
lib/scbi_mapreduce/work_manager.rb

Constant Summary collapse

@@job_id =
1
@@longest_processing_time =
0

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(objs) ⇒ WorkManagerData

Returns a new instance of WorkManagerData.



30
31
32
33
34
35
36
37
38
39
# File 'lib/scbi_mapreduce/work_manager.rb', line 30

def initialize(objs)

  @job_identifier=@@job_id
  @@job_id+=1
  @data=objs

  sent!
  @received_time=0
  @processing_time=nil
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



28
29
30
# File 'lib/scbi_mapreduce/work_manager.rb', line 28

def data
  @data
end

#job_identifierObject (readonly)

Returns the value of attribute job_identifier.



27
28
29
# File 'lib/scbi_mapreduce/work_manager.rb', line 27

def job_identifier
  @job_identifier
end

#received_timeObject

Returns the value of attribute received_time.



28
29
30
# File 'lib/scbi_mapreduce/work_manager.rb', line 28

def received_time
  @received_time
end

#sent_timeObject

Returns the value of attribute sent_time.



28
29
30
# File 'lib/scbi_mapreduce/work_manager.rb', line 28

def sent_time
  @sent_time
end

#statusObject

Returns the value of attribute status.



28
29
30
# File 'lib/scbi_mapreduce/work_manager.rb', line 28

def status
  @status
end

Class Method Details

.job_idObject



76
77
78
79
# File 'lib/scbi_mapreduce/work_manager.rb', line 76

def self.job_id
  # puts "Setting job_id to #{c}"
  @@job_id
end

.job_id=(c) ⇒ Object



71
72
73
74
# File 'lib/scbi_mapreduce/work_manager.rb', line 71

def self.job_id=(c)
  # puts "Setting job_id to #{c}"
  @@job_id=c
end

Instance Method Details

#inspectObject



66
67
68
69
# File 'lib/scbi_mapreduce/work_manager.rb', line 66

def inspect
  time="; time: #{processing_time} seg"
  return "WorkManagerData: #{@job_identifier} => #{@status} #{time}"
end

#processing_timeObject

return running or real processing time



62
63
64
# File 'lib/scbi_mapreduce/work_manager.rb', line 62

def processing_time
  return (@processing_time || (Time.now-@sent_time))
end

#received!(objs) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/scbi_mapreduce/work_manager.rb', line 41

def received!(objs)
  @data=objs
  @received_time=Time.now
  @processing_time=@received_time-@sent_time

  # save longer processing time
  @@longest_processing_time=[@@longest_processing_time,@processing_time].max

  @status=:received
end

#sent!Object



52
53
54
55
# File 'lib/scbi_mapreduce/work_manager.rb', line 52

def sent!
  @status=:running
  @sent_time=Time.now
end

#stuck?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/scbi_mapreduce/work_manager.rb', line 57

def stuck?
  (@status==:running) && (@@longest_processing_time>0) && (processing_time>(@@longest_processing_time*2))
end