Class: Emque::Consuming::Pidfile

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/emque/consuming/pidfile.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Pidfile

Returns a new instance of Pidfile.



12
13
14
15
16
# File 'lib/emque/consuming/pidfile.rb', line 12

def initialize(path)
  self.path = path
  ensure_dir_exists
  self.pid = File.read(path).to_i if File.exist?(path)
end

Instance Attribute Details

#pathObject

Returns the value of attribute path.



8
9
10
# File 'lib/emque/consuming/pidfile.rb', line 8

def path
  @path
end

Instance Method Details

#running?Boolean

Returns:

  • (Boolean)


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/emque/consuming/pidfile.rb', line 18

def running?
  if pid
    if pid == 0
      rm_file
    else
      begin
        Process.getpgid(pid)
        return true
      rescue Errno::ESRCH
        rm_file
      end
    end
  end
  false
end

#writeObject



34
35
36
37
38
# File 'lib/emque/consuming/pidfile.rb', line 34

def write
  File.open(path, "w") do |f|
    f.puts Process.pid
  end
end