Class: DeepConnect::Cron
Constant Summary collapse
- TAB =
[ [10, proc{|org, cron, t| cron.mon_10sec}], [60, proc{|org, cron, t| cron.mon_min}], [3060, proc{|org, cron, t| cron.mon_hour}], [Conf.KEEP_ALIVE_INTERVAL, proc{|org, cron, t| org.keep_alive}], ]
Instance Attribute Summary collapse
-
#timer ⇒ Object
(also: #tick)
readonly
Returns the value of attribute timer.
Instance Method Summary collapse
-
#initialize(organizer) ⇒ Cron
constructor
A new instance of Cron.
- #mon_10sec ⇒ Object
- #mon_hour ⇒ Object
- #mon_min ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(organizer) ⇒ Cron
Returns a new instance of Cron.
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/deep-connect/cron.rb', line 21 def initialize(organizer) @organizer = organizer @timer = 0 @last_exec_times = {} @mon_mutex = Mutex.new @prev_message10s = nil end |
Instance Attribute Details
#timer ⇒ Object (readonly) Also known as: tick
Returns the value of attribute timer.
32 33 34 |
# File 'lib/deep-connect/cron.rb', line 32 def timer @timer end |
Instance Method Details
#mon_10sec ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/deep-connect/cron.rb', line 57 def mon_10sec return if @organizer.deep_spaces.size == 0 if Conf.DISPLAY_MONITOR_MESSAGE str = "" str.concat "Connect DeepSpaces: BEGIN\n" for peer_id, ds in @organizer.deep_spaces.dup str.concat "#{peer_id.inspect} => \n" str.concat "\t#{ds}\n" end str.concat "Connect DeepSpaces: END\n" if @prev_message10s != str @prev_message10s = str puts "MON 10SEC: #{@timer}\n", str end end end |
#mon_hour ⇒ Object
82 83 84 85 86 |
# File 'lib/deep-connect/cron.rb', line 82 def mon_hour if Conf.DISPLAY_MONITOR_MESSAGE puts "MON HOUR: #{@timer}" end end |
#mon_min ⇒ Object
76 77 78 79 80 |
# File 'lib/deep-connect/cron.rb', line 76 def mon_min if Conf.DISPLAY_MONITOR_MESSAGE puts "MON MIN: #{@timer}" end end |
#start ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/deep-connect/cron.rb', line 35 def start Thread.start do loop do sleep Conf.MON_INTERVAL @timer += Conf.MON_INTERVAL Thread.start do @mon_mutex.synchronize do for tab in TAB last_time = @last_exec_times[tab] last_time = 0 unless last_time if @timer >= last_time + tab[0] @last_exec_times[tab] = @timer tab[1].call @organizer, self, @timer end end end end end end end |