Class: Emque::Consuming::Pidfile
- Inherits:
-
Object
- Object
- Emque::Consuming::Pidfile
- Extended by:
- Forwardable
- Defined in:
- lib/emque/consuming/pidfile.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#initialize(path) ⇒ Pidfile
constructor
A new instance of Pidfile.
- #running? ⇒ Boolean
- #write ⇒ Object
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
#path ⇒ Object
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
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 |
#write ⇒ Object
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 |