Module: Vidibus::Recording::Mongoid
- Extended by:
- ActiveSupport::Concern
- Included in:
- Recording
- Defined in:
- lib/vidibus/recording/mongoid.rb
Instance Method Summary collapse
-
#backend ⇒ Object
TODO: really a public method? Returns an instance of a fitting recording backend.
- #basename ⇒ Object
- #current_part ⇒ Object
-
#done? ⇒ Boolean
Returns true if recording has either been stopped or failed.
-
#fail(msg) ⇒ Object
Receives an error from recording worker and stores it.
-
#failed? ⇒ Boolean
Returns true if recording has failed.
-
#file ⇒ Object
Returns the file name of this recording.
-
#folder ⇒ Object
Return folder to store recordings in.
-
#halt(msg = nil) ⇒ Object
Gets called from recording worker if it receives no more data.
- #has_data? ⇒ Boolean
-
#log_file ⇒ Object
Returns the log file name for this recording.
-
#reset ⇒ Object
TODO: really a public method? Removes all acquired data!.
-
#restart ⇒ Object
Resets data and starts anew.
-
#resume ⇒ Object
Continue recording that is not running anymore.
-
#start(time = :now) ⇒ Object
Starts a recording worker now, unless it has been done already.
-
#started? ⇒ Boolean
Returns true if recording has been started.
-
#stop ⇒ Object
Stops the recording worker and starts postprocessing.
- #stopped? ⇒ Boolean
- #track_progress ⇒ Object
-
#worker ⇒ Object
TODO: really a public method? Returns an instance of the recording worker.
-
#worker_running? ⇒ Boolean
Returns true if recording worker is still running.
-
#yml_file ⇒ Object
Returns the YAML file name for this recording.
Instance Method Details
#backend ⇒ Object
TODO: really a public method? Returns an instance of a fitting recording backend.
122 123 124 125 126 127 128 |
# File 'lib/vidibus/recording/mongoid.rb', line 122 def backend @backend ||= Vidibus::Recording::Backend.load({ :stream => stream, :file => current_part.data_file, :live => true }) end |
#basename ⇒ Object
176 177 178 |
# File 'lib/vidibus/recording/mongoid.rb', line 176 def basename "#{folder}/#{uuid}" end |
#current_part ⇒ Object
197 198 199 |
# File 'lib/vidibus/recording/mongoid.rb', line 197 def current_part parts.last end |
#done? ⇒ Boolean
Returns true if recording has either been stopped or failed.
131 132 133 |
# File 'lib/vidibus/recording/mongoid.rb', line 131 def done? stopped? || failed? end |
#fail(msg) ⇒ Object
Receives an error from recording worker and stores it. The worker gets stopped and postprocessing is started.
85 86 87 88 89 90 91 92 93 |
# File 'lib/vidibus/recording/mongoid.rb', line 85 def fail(msg) return false unless running? worker.stop self.pid = nil self.error = msg self.failed_at = Time.now self.running = false postprocess end |
#failed? ⇒ Boolean
Returns true if recording has failed.
136 137 138 |
# File 'lib/vidibus/recording/mongoid.rb', line 136 def failed? !!failed_at end |
#file ⇒ Object
Returns the file name of this recording. DEPRECATED: this is kept for existing records only.
187 188 189 |
# File 'lib/vidibus/recording/mongoid.rb', line 187 def file @file ||= "#{basename}.rec" end |
#folder ⇒ Object
Return folder to store recordings in.
166 167 168 169 170 171 172 173 174 |
# File 'lib/vidibus/recording/mongoid.rb', line 166 def folder @folder ||= begin f = ['recordings'] f.unshift(Rails.root) if defined?(Rails) path = File.join(f) FileUtils.mkdir_p(path) unless File.exist?(path) path end end |
#halt(msg = nil) ⇒ Object
Gets called from recording worker if it receives no more data.
75 76 77 78 79 80 81 |
# File 'lib/vidibus/recording/mongoid.rb', line 75 def halt(msg = nil) return false unless running? worker.stop self.pid = nil self.running = false postprocess end |
#has_data? ⇒ Boolean
149 150 151 |
# File 'lib/vidibus/recording/mongoid.rb', line 149 def has_data? size.to_i > 0 end |
#log_file ⇒ Object
Returns the log file name for this recording.
181 182 183 |
# File 'lib/vidibus/recording/mongoid.rb', line 181 def log_file @log_file ||= "#{basename}.log" end |
#reset ⇒ Object
TODO: really a public method? Removes all acquired data!
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/vidibus/recording/mongoid.rb', line 97 def reset remove_files blank = {} [ :started_at, :stopped_at, :failed_at, :info, :error, :size, :duration, :monitoring_job_identifier ].map {|a| blank[a] = nil } update_attributes!(blank) destroy_all_parts end |
#restart ⇒ Object
Resets data and starts anew.
57 58 59 60 61 |
# File 'lib/vidibus/recording/mongoid.rb', line 57 def restart stop reset start end |
#resume ⇒ Object
Continue recording that is not running anymore.
47 48 49 50 51 52 53 54 |
# File 'lib/vidibus/recording/mongoid.rb', line 47 def resume return false if running? || !started? self.stopped_at = nil self.failed_at = nil start_worker start_monitoring_job save! end |
#start(time = :now) ⇒ Object
Starts a recording worker now, unless it has been done already. Provide a Time object to schedule start.
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/vidibus/recording/mongoid.rb', line 34 def start(time = :now) return false if done? || started? if time == :now self.started_at = Time.now start_worker start_monitoring_job save! else schedule(time) end end |
#started? ⇒ Boolean
Returns true if recording has been started.
141 142 143 |
# File 'lib/vidibus/recording/mongoid.rb', line 141 def started? !!started_at end |
#stop ⇒ Object
Stops the recording worker and starts postprocessing.
64 65 66 67 68 69 70 71 72 |
# File 'lib/vidibus/recording/mongoid.rb', line 64 def stop return false if done? || !started? worker.stop self.pid = nil self.stopped_at = Time.now self.running = false self.monitoring_job_identifier = nil postprocess end |
#stopped? ⇒ Boolean
145 146 147 |
# File 'lib/vidibus/recording/mongoid.rb', line 145 def stopped? !!stopped_at end |
#track_progress ⇒ Object
201 202 203 204 205 206 |
# File 'lib/vidibus/recording/mongoid.rb', line 201 def track_progress current_part.track_progress if current_part set_size set_duration save! end |
#worker ⇒ Object
TODO: really a public method? Returns an instance of the recording worker.
116 117 118 |
# File 'lib/vidibus/recording/mongoid.rb', line 116 def worker @worker ||= Vidibus::Recording::Worker.new(self) end |
#worker_running? ⇒ Boolean
Returns true if recording worker is still running. Persists attributes accordingly.
155 156 157 158 159 160 161 162 163 |
# File 'lib/vidibus/recording/mongoid.rb', line 155 def worker_running? if worker.running? update_attributes(:running => true) unless running? true else update_attributes(:pid => nil, :running => false) false end end |
#yml_file ⇒ Object
Returns the YAML file name for this recording. DEPRECATED: this is kept for existing records only.
193 194 195 |
# File 'lib/vidibus/recording/mongoid.rb', line 193 def yml_file @yml_file ||= "#{basename}.yml" end |