Class: Nasty::BackgroundJob

Inherits:
Object show all
Defined in:
lib/nasty/background_job.rb

Instance Method Summary collapse

Constructor Details

#initialize(process) ⇒ BackgroundJob

Returns a new instance of BackgroundJob.



3
4
5
# File 'lib/nasty/background_job.rb', line 3

def initialize(process)
  @process = process
end

Instance Method Details

#runObject



7
8
9
10
11
# File 'lib/nasty/background_job.rb', line 7

def run
  @pid = fork do
    exec @process
  end
end

#stop(signal = "TERM") ⇒ Object



13
14
15
16
17
18
# File 'lib/nasty/background_job.rb', line 13

def stop(signal = "TERM")
  if @pid
    Process.kill(signal, @pid)
    Process.wait(@pid)
  end
end