Class: Ant::DRY::Daemon

Inherits:
Object
  • Object
show all
Defined in:
lib/ant/dry/daemon.rb

Instance Method Summary collapse

Constructor Details

#initialize(wait_time, attach, proc) ⇒ Daemon

Returns a new instance of Daemon.



4
5
6
7
8
9
# File 'lib/ant/dry/daemon.rb', line 4

def initialize(wait_time, attach, proc)
  @proc = proc
  @wait_time = wait_time
  @attach = attach
  @finish = false
end

Instance Method Details

#runObject



22
23
24
25
26
27
28
# File 'lib/ant/dry/daemon.rb', line 22

def run
  if @attach
    task
  else
    Thread.new(&:task)
  end
end

#taskObject



11
12
13
14
15
16
17
18
19
20
# File 'lib/ant/dry/daemon.rb', line 11

def task
  loop do
    begin
      @proc.exec
    rescue StandarError => ex
      log_error('Unexpected error', error: ex)
    end
    sleep(@wait_time)
  end
end