Class: Zold::Routines

Inherits:
Object
  • Object
show all
Defined in:
lib/zold/routines.rb

Overview

NODE command

Instance Method Summary collapse

Constructor Details

#initialize(log = Log::Quiet.new) ⇒ Routines

Returns a new instance of Routines.



31
32
33
34
# File 'lib/zold/routines.rb', line 31

def initialize(log = Log::Quiet.new)
  @log = log
  @threads = []
end

Instance Method Details

#add(minutes = 1) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/zold/routines.rb', line 36

def add(minutes = 1)
  @threads << Thread.start do
    VerboseThread.new(@log).run(true) do
      Thread.current.name = 'routines'
      count = 0
      loop do
        sleep(minutes * 60)
        yield count
        count += 1
      end
    end
  end
end

#stopObject



50
51
52
53
54
55
56
# File 'lib/zold/routines.rb', line 50

def stop
  @threads.each do |t|
    t.exit
    @log.debug("#{t.name} thread stopped")
  end
  @log.info("#{@threads.count} routine threads stopped")
end