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
- STOP_TIMEOUT =
START_TIMEOUT = 20
10
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.
12 13 14 15 16 |
# File 'lib/vidibus/recording/worker.rb', line 12 def initialize(recording) self.recording = recording self.pid = recording.pid self. = nil end |
Instance Attribute Details
#metadata ⇒ Object
Returns the value of attribute metadata.
10 11 12 |
# File 'lib/vidibus/recording/worker.rb', line 10 def end |
#pid ⇒ Object
Returns the value of attribute pid.
10 11 12 |
# File 'lib/vidibus/recording/worker.rb', line 10 def pid @pid end |
#recording ⇒ Object
Returns the value of attribute recording.
10 11 12 |
# File 'lib/vidibus/recording/worker.rb', line 10 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
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/vidibus/recording/worker.rb', line 18 def start self.pid = fork do begin record rescue => e fail(e.inspect) end end Process.detach(pid) pid end |
#stop ⇒ Object
30 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 30 def stop if running? begin Timeout::timeout(STOP_TIMEOUT) do begin log("Stopping process #{pid}...") # Use SIGQUIT to terminate because DelayedJob traps INT and TERM Process.kill('SIGQUIT', 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 |