Class: Vidibus::Recording::Worker
- Inherits:
-
Object
- Object
- Vidibus::Recording::Worker
- Defined in:
- lib/vidibus/recording/worker.rb
Defined Under Namespace
Classes: ProcessError
Constant Summary collapse
- START_TIMEOUT =
20
- STOP_TIMEOUT =
2
Instance Attribute Summary collapse
-
#metadata ⇒ Object
Returns the value of attribute metadata.
-
#pid ⇒ Object
Returns the value of attribute pid.
-
#recording ⇒ Object
Returns the value of attribute recording.
Instance Method Summary collapse
-
#initialize(recording) ⇒ Worker
constructor
A new instance of Worker.
- #running? ⇒ Boolean
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(recording) ⇒ Worker
Returns a new instance of Worker.
13 14 15 16 17 |
# File 'lib/vidibus/recording/worker.rb', line 13 def initialize(recording) self.recording = recording self.pid = recording.pid self. = nil end |
Instance Attribute Details
#metadata ⇒ Object
Returns the value of attribute metadata.
11 12 13 |
# File 'lib/vidibus/recording/worker.rb', line 11 def @metadata end |
#pid ⇒ Object
Returns the value of attribute pid.
11 12 13 |
# File 'lib/vidibus/recording/worker.rb', line 11 def pid @pid end |
#recording ⇒ Object
Returns the value of attribute recording.
11 12 13 |
# File 'lib/vidibus/recording/worker.rb', line 11 def recording @recording end |
Instance Method Details
#running? ⇒ Boolean
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/vidibus/recording/worker.rb', line 57 def running? return false unless pid begin Process.kill(0, pid) return true rescue Errno::ESRCH return false rescue Errno::EPERM raise ProcessError.new("No permission to check process #{pid}") rescue raise ProcessError.new("Unable to determine status of process #{pid}: #{$!}") end end |
#start ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/vidibus/recording/worker.rb', line 19 def start self.pid = fork do begin record rescue => e fail(e.inspect) end end Process.detach(pid) pid end |
#stop ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/vidibus/recording/worker.rb', line 31 def stop if running? begin Timeout::timeout(STOP_TIMEOUT) do begin log("Stopping process #{pid}...") Process.kill('SIGTERM', pid) Process.wait(pid) log('STOPPED') rescue Errno::ECHILD log('STOPPED') end end rescue Timeout::Error begin log("Killing process #{pid}") Process.kill('KILL', pid) Process.wait(pid) log('KILLED') rescue Errno::ECHILD log('KILLED') end end end end |