Module: Vidibus::Recording::Mongoid

Extended by:
ActiveSupport::Concern
Included in:
Recording
Defined in:
lib/vidibus/recording/mongoid.rb

Instance Method Summary collapse

Instance Method Details

#backendObject

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

#basenameObject



176
177
178
# File 'lib/vidibus/recording/mongoid.rb', line 176

def basename
  "#{folder}/#{uuid}"
end

#current_partObject



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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


136
137
138
# File 'lib/vidibus/recording/mongoid.rb', line 136

def failed?
  !!failed_at
end

#fileObject

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

#folderObject

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

Returns:

  • (Boolean)


149
150
151
# File 'lib/vidibus/recording/mongoid.rb', line 149

def has_data?
  size.to_i > 0
end

#log_fileObject

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

#resetObject

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

#restartObject

Resets data and starts anew.



57
58
59
60
61
# File 'lib/vidibus/recording/mongoid.rb', line 57

def restart
  stop
  reset
  start
end

#resumeObject

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.

Returns:

  • (Boolean)


141
142
143
# File 'lib/vidibus/recording/mongoid.rb', line 141

def started?
  !!started_at
end

#stopObject

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

Returns:

  • (Boolean)


145
146
147
# File 'lib/vidibus/recording/mongoid.rb', line 145

def stopped?
  !!stopped_at
end

#track_progressObject



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

#workerObject

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.

Returns:

  • (Boolean)


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_fileObject

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